Opus
IETF low-delay audio codec: API and operations manual
1.0.1
 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);
351 typedef struct OpusDecoder OpusDecoder;
352 
357 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
358 
372 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
373  opus_int32 Fs,
374  int channels,
375  int *error
376 );
377 
387 OPUS_EXPORT int opus_decoder_init(
388  OpusDecoder *st,
389  opus_int32 Fs,
390  int channels
391 ) OPUS_ARG_NONNULL(1);
392 
405 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
406  OpusDecoder *st,
407  const unsigned char *data,
408  opus_int32 len,
409  opus_int16 *pcm,
410  int frame_size,
411  int decode_fec
412 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
413 
426 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
427  OpusDecoder *st,
428  const unsigned char *data,
429  opus_int32 len,
430  float *pcm,
431  int frame_size,
432  int decode_fec
433 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
434 
441 OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
442 
446 OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
447 
461 OPUS_EXPORT int opus_packet_parse(
462  const unsigned char *data,
463  opus_int32 len,
464  unsigned char *out_toc,
465  const unsigned char *frames[48],
466  short size[48],
467  int *payload_offset
468 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
469 
479 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1);
480 
487 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
488 
494 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1);
495 
502 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
503 
511 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);
523 
524 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
525 
526 OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
527 
528 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
529 
530 OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
531 
532 OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
533 
534 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);
535 
536 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
537 
538 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
539 
542 #ifdef __cplusplus
543 }
544 #endif
545 
546 #endif /* OPUS_H */
For more information visit the Opus Website.