Opus
IETF low-delay audio codec: API and operations manual
0.9.14
 All Files Functions Typedefs Macros Groups Pages
opus.h
Go to the documentation of this file.
1 /* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
2  Written by Jean-Marc Valin and Koen Vos */
3 /*
4  Redistribution and use in source and binary forms, with or without
5  modification, are permitted provided that the following conditions
6  are met:
7 
8  - Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 
11  - Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
33 #ifndef OPUS_H
34 #define OPUS_H
35 
36 #include "opus_types.h"
37 #include "opus_defines.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
162 typedef struct OpusEncoder OpusEncoder;
163 
164 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels);
165 
199 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
200  opus_int32 Fs,
201  int channels,
202  int application,
203  int *error
204 );
205 
217 OPUS_EXPORT int opus_encoder_init(
218  OpusEncoder *st,
219  opus_int32 Fs,
220  int channels,
221  int application
222 ) OPUS_ARG_NONNULL(1);
223 
236 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
237  OpusEncoder *st,
238  const opus_int16 *pcm,
239  int frame_size,
240  unsigned char *data,
241  opus_int32 max_data_bytes
242 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
243 
261 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(
262  OpusEncoder *st,
263  const float *pcm,
264  int frame_size,
265  unsigned char *data,
266  opus_int32 max_data_bytes
267 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
268 
272 OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
273 
280 OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
339 typedef struct OpusDecoder OpusDecoder;
340 
345 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
346 
360 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
361  opus_int32 Fs,
362  int channels,
363  int *error
364 );
365 
375 OPUS_EXPORT int opus_decoder_init(
376  OpusDecoder *st,
377  opus_int32 Fs,
378  int channels
379 ) OPUS_ARG_NONNULL(1);
380 
393 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
394  OpusDecoder *st,
395  const unsigned char *data,
396  opus_int32 len,
397  opus_int16 *pcm,
398  int frame_size,
399  int decode_fec
400 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
401 
414 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
415  OpusDecoder *st,
416  const unsigned char *data,
417  opus_int32 len,
418  float *pcm,
419  int frame_size,
420  int decode_fec
421 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
422 
429 OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
430 
434 OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
435 
449 OPUS_EXPORT int opus_packet_parse(
450  const unsigned char *data,
451  opus_int32 len,
452  unsigned char *out_toc,
453  const unsigned char *frames[48],
454  short size[48],
455  int *payload_offset
456 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
457 
467 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1);
468 
475 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
476 
482 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1);
483 
490 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
491 
499 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
511 
512 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
513 
514 OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
515 
516 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
517 
518 OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
519 
520 OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
521 
522 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
523 
524 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
525 
526 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
527 
530 #ifdef __cplusplus
531 }
532 #endif
533 
534 #endif /* OPUS_H */
For more information visit the Opus Website.