opusfile  0.1
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 # include <stdarg.h>
20 
56 # if defined(__cplusplus)
57 extern "C" {
58 # endif
59 
60 # include <stdio.h>
61 # include <ogg/ogg.h>
62 # include <opus_multistream.h>
63 
64 /*Enable special features for gcc and gcc-compatible compilers.*/
65 # if !defined(OP_GNUC_PREREQ)
66 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
67 # define OP_GNUC_PREREQ(_maj,_min) \
68  ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
69 # else
70 # define OP_GNUC_PREREQ(_maj,_min) 0
71 # endif
72 # endif
73 
74 # if OP_GNUC_PREREQ(4,0)
75 # pragma GCC visibility push(default)
76 # endif
77 
78 typedef struct OpusHead OpusHead;
79 typedef struct OpusTags OpusTags;
80 typedef struct OggOpusFile OggOpusFile;
81 
82 /*Warning attributes for libopusfile functions.*/
83 # if OP_GNUC_PREREQ(3,4)
84 # define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
85 # else
86 # define OP_WARN_UNUSED_RESULT
87 # endif
88 # if OP_GNUC_PREREQ(3,4)
89 # define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x)))
90 # else
91 # define OP_ARG_NONNULL(_x)
92 # endif
93 
103 
105 #define OP_FALSE (-1)
106 /*Currently not used externally.*/
107 #define OP_EOF (-2)
108 
110 #define OP_HOLE (-3)
111 
113 #define OP_EREAD (-128)
114 
117 #define OP_EFAULT (-129)
118 
120 #define OP_EIMPL (-130)
121 
122 #define OP_EINVAL (-131)
123 
127 #define OP_ENOTFORMAT (-132)
128 
130 #define OP_EBADHEADER (-133)
131 
132 #define OP_EVERSION (-134)
133 /*Currently not used at all.*/
134 #define OP_ENOTAUDIO (-135)
135 
138 #define OP_EBADPACKET (-136)
139 
142 #define OP_EBADLINK (-137)
143 
144 #define OP_ENOSEEK (-138)
145 
146 #define OP_EBADTIMESTAMP (-139)
147 
150 
153 
155 #define OPUS_CHANNEL_COUNT_MAX (255)
156 
160 struct OpusHead{
170  int version;
175  unsigned pre_skip;
182  opus_uint32 input_sample_rate;
212 };
213 
244 struct OpusTags{
250  int comments;
253  char *vendor;
254 };
255 
264 
290 OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head,
291  const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
292 
307 ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp)
308  OP_ARG_NONNULL(1);
309 
324 OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags,
325  const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
326 
331 void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1);
332 
344 int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value)
345  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3);
346 
357 int opus_tags_add_comment(OpusTags *_tags,const char *_comment)
358  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
359 
375 const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count)
376  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
377 
385 int opus_tags_query_count(const OpusTags *_tags,const char *_tag)
386  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
387 
393 void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1);
394 
398 
410 
411 /*These are the raw numbers used to define the request codes.
412  They should not be used directly.*/
413 #define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464)
414 #define OP_HTTP_PROXY_HOST_REQUEST (6528)
415 #define OP_HTTP_PROXY_PORT_REQUEST (6592)
416 #define OP_HTTP_PROXY_USER_REQUEST (6656)
417 #define OP_HTTP_PROXY_PASS_REQUEST (6720)
418 
419 #define OP_URL_OPT(_request) ((_request)+(char *)0)
420 
421 /*These macros trigger compilation errors or warnings if the wrong types are
422  provided to one of the URL options.*/
423 #define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x))
424 #define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x)))
425 
432 #define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \
433  OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b)
434 
443 #define OP_HTTP_PROXY_HOST(_host) \
444  OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
445 
456 #define OP_HTTP_PROXY_PORT(_port) \
457  OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port)
458 
469 #define OP_HTTP_PROXY_USER(_user) \
470  OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
471 
482 #define OP_HTTP_PROXY_PASS(_pass) \
483  OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
484 
487 
499 
500 typedef struct OpusFileCallbacks OpusFileCallbacks;
501 
510 typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes);
511 
521 typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence);
522 
525 typedef opus_int64 (*op_tell_func)(void *_stream);
526 
531 typedef int (*op_close_func)(void *_stream);
532 
555 };
556 
570 OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb,
571  const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2)
572  OP_ARG_NONNULL(3);
573 
587 OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb,
588  int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3);
589 
605 OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb,
606  const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1)
607  OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4);
608 
619 OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb,
620  const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1);
621 
640 OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb,
641  const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
642 
657 OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb,
658  const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
659 
662 
672 
703 int op_test(OpusHead *_head,
704  const unsigned char *_initial_data,size_t _initial_bytes);
705 
715 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error)
716  OP_ARG_NONNULL(1);
717 
726 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data,
727  size_t _size,int *_error);
728 
750 OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url,
751  int *_error,va_list _ap) OP_ARG_NONNULL(1);
752 
769 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url,
770  int *_error,...) OP_ARG_NONNULL(1);
771 
845 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_source,
846  const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
847  size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
848 
859 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error)
860  OP_ARG_NONNULL(1);
861 
871 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data,
872  size_t _size,int *_error);
873 
897 OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url,
898  int *_error,va_list _ap) OP_ARG_NONNULL(1);
899 
916 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url,
917  int *_error,...) OP_ARG_NONNULL(1);
918 
978 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_source,
979  const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
980  size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
981 
1008 int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1);
1009 
1012 void op_free(OggOpusFile *_of);
1013 
1016 
1034 
1049 int op_seekable(OggOpusFile *_of) OP_ARG_NONNULL(1);
1050 
1059 int op_link_count(OggOpusFile *_of) OP_ARG_NONNULL(1);
1060 
1074 opus_uint32 op_serialno(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1075 
1091 int op_channel_count(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1092 
1109 opus_int64 op_raw_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1110 
1127 ogg_int64_t op_pcm_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1128 
1143 const OpusHead *op_head(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1144 
1161 const OpusTags *op_tags(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1162 
1178 int op_current_link(OggOpusFile *_of) OP_ARG_NONNULL(1);
1179 
1191 opus_int32 op_bitrate(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1192 
1204 opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1);
1205 
1210 opus_int64 op_raw_tell(OggOpusFile *_of) OP_ARG_NONNULL(1);
1211 
1219 ogg_int64_t op_pcm_tell(OggOpusFile *_of) OP_ARG_NONNULL(1);
1220 
1223 
1251 
1265 int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1);
1266 
1281 int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1);
1282 
1285 
1325 
1406 OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of,
1407  opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
1408 
1487 OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of,
1488  float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
1489 
1548 OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of,
1549  opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1);
1550 
1609 OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of,
1610  float *_pcm,int _buf_size) OP_ARG_NONNULL(1);
1611 
1614 
1615 # if OP_GNUC_PREREQ(4,0)
1616 # pragma GCC visibility pop
1617 # endif
1618 
1619 # if defined(__cplusplus)
1620 }
1621 # endif
1622 
1623 #endif