| OLD | NEW |
| (Empty) | |
| 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 |
| 28 /** |
| 29 * @file opus.h |
| 30 * @brief Opus reference implementation API |
| 31 */ |
| 32 |
| 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 |
| 43 /** |
| 44 * @mainpage Opus |
| 45 * |
| 46 * The Opus codec is designed for interactive speech and audio transmission over
the Internet. |
| 47 * It is designed by the IETF Codec Working Group and incorporates technology fr
om |
| 48 * Skype's SILK codec and Xiph.Org's CELT codec. |
| 49 * |
| 50 * The Opus codec is designed to handle a wide range of interactive audio applic
ations, |
| 51 * including Voice over IP, videoconferencing, in-game chat, and even remote liv
e music |
| 52 * performances. It can scale from low bit-rate narrowband speech to very high q
uality |
| 53 * stereo music. Its main features are: |
| 54 |
| 55 * @li Sampling rates from 8 to 48 kHz |
| 56 * @li Bit-rates from 6 kb/s to 510 kb/s |
| 57 * @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR) |
| 58 * @li Audio bandwidth from narrowband to full-band |
| 59 * @li Support for speech and music |
| 60 * @li Support for mono and stereo |
| 61 * @li Support for multichannel (up to 255 channels) |
| 62 * @li Frame sizes from 2.5 ms to 60 ms |
| 63 * @li Good loss robustness and packet loss concealment (PLC) |
| 64 * @li Floating point and fixed-point implementation |
| 65 * |
| 66 * Documentation sections: |
| 67 * @li @ref opus_encoder |
| 68 * @li @ref opus_decoder |
| 69 * @li @ref opus_repacketizer |
| 70 * @li @ref opus_libinfo |
| 71 * @li @ref opus_custom |
| 72 */ |
| 73 |
| 74 /** @defgroup opus_encoder Opus Encoder |
| 75 * @{ |
| 76 * |
| 77 * @brief This page describes the process and functions used to encode Opus. |
| 78 * |
| 79 * Since Opus is a stateful codec, the encoding process starts with creating an
encoder |
| 80 * state. This can be done with: |
| 81 * |
| 82 * @code |
| 83 * int error; |
| 84 * OpusEncoder *enc; |
| 85 * enc = opus_encoder_create(Fs, channels, application, &error); |
| 86 * @endcode |
| 87 * |
| 88 * From this point, @c enc can be used for encoding an audio stream. An encoder
state |
| 89 * @b must @b not be used for more than one stream at the same time. Similarly,
the encoder |
| 90 * state @b must @b not be re-initialized for each frame. |
| 91 * |
| 92 * While opus_encoder_create() allocates memory for the state, it's also possib
le |
| 93 * to initialize pre-allocated memory: |
| 94 * |
| 95 * @code |
| 96 * int size; |
| 97 * int error; |
| 98 * OpusEncoder *enc; |
| 99 * size = opus_encoder_get_size(channels); |
| 100 * enc = malloc(size); |
| 101 * error = opus_encoder_init(enc, Fs, channels, application); |
| 102 * @endcode |
| 103 * |
| 104 * where opus_encoder_get_size() returns the required size for the encoder stat
e. Note that |
| 105 * future versions of this code may change the size, so no assuptions should be
made about it. |
| 106 * |
| 107 * The encoder state is always continuous in memory and only a shallow copy is
sufficient |
| 108 * to copy it (e.g. memcpy()) |
| 109 * |
| 110 * It is possible to change some of the encoder's settings using the opus_encod
er_ctl() |
| 111 * interface. All these settings already default to the recommended value, so t
hey should |
| 112 * only be changed when necessary. The most common settings one may want to cha
nge are: |
| 113 * |
| 114 * @code |
| 115 * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); |
| 116 * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); |
| 117 * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); |
| 118 * @endcode |
| 119 * |
| 120 * where |
| 121 * |
| 122 * @arg bitrate is in bits per second (b/s) |
| 123 * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity an
d 10 is the highest |
| 124 * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_S
IGNAL_MUSIC |
| 125 * |
| 126 * See @ref opus_encoderctls and @ref opus_genericctls for a complete list of p
arameters that can be set or queried. Most parameters can be set or changed at a
ny time during a stream. |
| 127 * |
| 128 * To encode a frame, opus_encode() or opus_encode_float() must be called with
exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: |
| 129 * @code |
| 130 * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); |
| 131 * @endcode |
| 132 * |
| 133 * where |
| 134 * <ul> |
| 135 * <li>audio_frame is the audio data in opus_int16 (or float for opus_encode_fl
oat())</li> |
| 136 * <li>frame_size is the duration of the frame in samples (per channel)</li> |
| 137 * <li>packet is the byte array to which the compressed data is written</li> |
| 138 * <li>max_packet is the maximum number of bytes that can be written in the pac
ket (4000 bytes is recommended)</li> |
| 139 * </ul> |
| 140 * |
| 141 * opus_encode() and opus_encode_frame() return the number of bytes actually wr
itten to the packet. |
| 142 * The return value <b>can be negative</b>, which indicates that an error has o
ccurred. If the return value |
| 143 * is 1 byte, then the packet does not need to be transmitted (DTX). |
| 144 * |
| 145 * Once the encoder state if no longer needed, it can be destroyed with |
| 146 * |
| 147 * @code |
| 148 * opus_encoder_destroy(enc); |
| 149 * @endcode |
| 150 * |
| 151 * If the encoder was created with opus_encoder_init() rather than opus_encoder
_create(), |
| 152 * then no action is required aside from potentially freeing the memory that wa
s manually |
| 153 * allocated for it (calling free(enc) for the example above) |
| 154 * |
| 155 */ |
| 156 |
| 157 /** Opus encoder state. |
| 158 * This contains the complete state of an Opus encoder. |
| 159 * It is position independent and can be freely copied. |
| 160 * @see opus_encoder_create,opus_encoder_init |
| 161 */ |
| 162 typedef struct OpusEncoder OpusEncoder; |
| 163 |
| 164 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels); |
| 165 |
| 166 /** |
| 167 */ |
| 168 |
| 169 /** Allocates and initializes an encoder state. |
| 170 * There are three coding modes: |
| 171 * |
| 172 * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice |
| 173 * signals. It enhances the input signal by high-pass filtering and |
| 174 * emphasizing formants and harmonics. Optionally it includes in-band |
| 175 * forward error correction to protect against packet loss. Use this |
| 176 * mode for typical VoIP applications. Because of the enhancement, |
| 177 * even at high bitrates the output may sound different from the input. |
| 178 * |
| 179 * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most |
| 180 * non-voice signals like music. Use this mode for music and mixed |
| 181 * (music/voice) content, broadcast, and applications requiring less |
| 182 * than 15 ms of coding delay. |
| 183 * |
| 184 * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that |
| 185 * disables the speech-optimized mode in exchange for slightly reduced delay. |
| 186 * This mode can only be set on an newly initialized or freshly reset encoder |
| 187 * because it changes the codec delay. |
| 188 * |
| 189 * This is useful when the caller knows that the speech-optimized modes will not
be needed (use with caution). |
| 190 * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz) |
| 191 * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal |
| 192 * @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION_VOIP
/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY) |
| 193 * @param [out] error <tt>int*</tt>: @ref opus_errorcodes |
| 194 * @note Regardless of the sampling rate and number channels selected, the Opus
encoder |
| 195 * can switch to a lower audio audio bandwidth or number of channels if the bitr
ate |
| 196 * selected is too low. This also means that it is safe to always use 48 kHz ste
reo input |
| 197 * and let the encoder optimize the encoding. |
| 198 */ |
| 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 |
| 206 /** Initializes a previously allocated encoder state |
| 207 * The memory pointed to by st must be the size returned by opus_encoder_get_si
ze. |
| 208 * This is intended for applications which use their own allocator instead of m
alloc. |
| 209 * @see opus_encoder_create(),opus_encoder_get_size() |
| 210 * To reset a previously initialized state use the OPUS_RESET_STATE CTL. |
| 211 * @param [in] st <tt>OpusEncoder*</tt>: Encoder state |
| 212 * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz) |
| 213 * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal |
| 214 * @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOIP/OPU
S_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY) |
| 215 * @retval OPUS_OK Success or @ref opus_errorcodes |
| 216 */ |
| 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 |
| 224 /** Encodes an Opus frame. |
| 225 * The passed frame_size must an opus frame size for the encoder's sampling rat
e. |
| 226 * For example, at 48kHz the permitted values are 120, 240, 480, 960, 1920, and
2880. |
| 227 * Passing in a duration of less than 10ms (480 samples at 48kHz) will |
| 228 * prevent the encoder from using the LPC or hybrid modes. |
| 229 * @param [in] st <tt>OpusEncoder*</tt>: Encoder state |
| 230 * @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 channel
s). length is frame_size*channels*sizeof(opus_int16) |
| 231 * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input si
gnal |
| 232 * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes lo
ng) |
| 233 * @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for payload
; don't use for controlling bitrate |
| 234 * @returns length of the data payload (in bytes) or @ref opus_errorcodes |
| 235 */ |
| 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 |
| 244 /** Encodes an Opus frame from floating point input. |
| 245 * The passed frame_size must an opus frame size for the encoder's sampling rat
e. |
| 246 * For example, at 48kHz the permitted values are 120, 240, 480, 960, 1920, and
2880. |
| 247 * Passing in a duration of less than 10ms (480 samples at 48kHz) will |
| 248 * prevent the encoder from using the LPC or hybrid modes. |
| 249 * @param [in] st <tt>OpusEncoder*</tt>: Encoder state |
| 250 * @param [in] pcm <tt>float*</tt>: Input in float format (interleaved if 2 cha
nnels), with a normal range of +/-1.0. |
| 251 * Samples with a range beyond +/-1.0 are supported but will |
| 252 * be clipped by decoders using the integer API and should |
| 253 * only be used if it is known that the far end supports |
| 254 * extended dynamic range. |
| 255 * length is frame_size*channels*sizeof(float) |
| 256 * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input si
gnal |
| 257 * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes lo
ng) |
| 258 * @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for payload
; don't use for controlling bitrate |
| 259 * @returns length of the data payload (in bytes) or @ref opus_errorcodes |
| 260 */ |
| 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 |
| 269 /** Frees an OpusEncoder allocated by opus_encoder_create. |
| 270 * @param[in] st <tt>OpusEncoder*</tt>: State to be freed. |
| 271 */ |
| 272 OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); |
| 273 |
| 274 /** Perform a CTL function on an Opus encoder. |
| 275 * |
| 276 * Generally the request and subsequent arguments are generated |
| 277 * by a convenience macro. |
| 278 * @see opus_encoderctls |
| 279 */ |
| 280 OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NON
NULL(1); |
| 281 /**@}*/ |
| 282 |
| 283 /** @defgroup opus_decoder Opus Decoder |
| 284 * @{ |
| 285 * |
| 286 * @brief This page describes the process and functions used to decode Opus. |
| 287 * |
| 288 * The decoding process also starts with creating a decoder |
| 289 * state. This can be done with: |
| 290 * @code |
| 291 * int error; |
| 292 * OpusDecoder *dec; |
| 293 * dec = opus_decoder_create(Fs, channels, &error); |
| 294 * @endcode |
| 295 * where |
| 296 * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 |
| 297 * @li channels is the number of channels (1 or 2) |
| 298 * @li error will hold the error code in case or failure (or OPUS_OK on success
) |
| 299 * @li the return value is a newly created decoder state to be used for decodin
g |
| 300 * |
| 301 * While opus_decoder_create() allocates memory for the state, it's also possib
le |
| 302 * to initialize pre-allocated memory: |
| 303 * @code |
| 304 * int size; |
| 305 * int error; |
| 306 * OpusDecoder *dec; |
| 307 * size = opus_decoder_get_size(channels); |
| 308 * dec = malloc(size); |
| 309 * error = opus_decoder_init(dec, Fs, channels); |
| 310 * @endcode |
| 311 * where opus_decoder_get_size() returns the required size for the decoder stat
e. Note that |
| 312 * future versions of this code may change the size, so no assuptions should be
made about it. |
| 313 * |
| 314 * The decoder state is always continuous in memory and only a shallow copy is
sufficient |
| 315 * to copy it (e.g. memcpy()) |
| 316 * |
| 317 * To decode a frame, opus_decode() or opus_decode_float() must be called with
a packet of compressed audio data: |
| 318 * @code |
| 319 * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); |
| 320 * @endcode |
| 321 * where |
| 322 * |
| 323 * @li packet is the byte array containing the compressed data |
| 324 * @li len is the exact number of bytes contained in the packet |
| 325 * @li decoded is the decoded audio data in opus_int16 (or float for opus_decod
e_float()) |
| 326 * @li max_size is the max duration of the frame in samples (per channel) that
can fit into the decoded_frame array |
| 327 * |
| 328 * opus_decode() and opus_decode_float() return the number of samples (per chan
nel) decoded from the packet. |
| 329 * If that value is negative, then an error has occured. This can occur if the
packet is corrupted or if the audio |
| 330 * buffer is too small to hold the decoded audio. |
| 331 * |
| 332 * Opus is a stateful codec with overlapping blocks and as a result Opus |
| 333 * packets are not coded independently of each other. Packets must be |
| 334 * passed into the decoder serially and in the correct order for a correct |
| 335 * decode. Lost packets can be replaced with loss concealment by calling |
| 336 * the decoder with a null pointer and zero length for the missing packet. |
| 337 * |
| 338 * A single codec state may only be accessed from a single thread at |
| 339 * a time and any required locking must be performed by the caller. Separate |
| 340 * streams must be decoded with separate decoder states and can be decoded |
| 341 * in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK |
| 342 * defined. |
| 343 * |
| 344 */ |
| 345 |
| 346 /** Opus decoder state. |
| 347 * This contains the complete state of an Opus decoder. |
| 348 * It is position independent and can be freely copied. |
| 349 * @see opus_decoder_create,opus_decoder_init |
| 350 */ |
| 351 typedef struct OpusDecoder OpusDecoder; |
| 352 |
| 353 /** Gets the size of an OpusDecoder structure. |
| 354 * @param [in] channels <tt>int</tt>: Number of channels |
| 355 * @returns size |
| 356 */ |
| 357 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels); |
| 358 |
| 359 /** Allocates and initializes a decoder state. |
| 360 * @param [in] Fs <tt>opus_int32</tt>: Sample rate to decode at (Hz) |
| 361 * @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode |
| 362 * @param [out] error <tt>int*</tt>: OPUS_OK Success or @ref opus_errorcodes |
| 363 * |
| 364 * Internally Opus stores data at 48000 Hz, so that should be the default |
| 365 * value for Fs. However, the decoder can efficiently decode to buffers |
| 366 * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use |
| 367 * data at the full sample rate, or knows the compressed data doesn't |
| 368 * use the full frequency range, it can request decoding at a reduced |
| 369 * rate. Likewise, the decoder is capable of filling in either mono or |
| 370 * interleaved stereo pcm buffers, at the caller's request. |
| 371 */ |
| 372 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( |
| 373 opus_int32 Fs, |
| 374 int channels, |
| 375 int *error |
| 376 ); |
| 377 |
| 378 /** Initializes a previously allocated decoder state. |
| 379 * The state must be the size returned by opus_decoder_get_size. |
| 380 * This is intended for applications which use their own allocator instead of m
alloc. @see opus_decoder_create,opus_decoder_get_size |
| 381 * To reset a previously initialized state use the OPUS_RESET_STATE CTL. |
| 382 * @param [in] st <tt>OpusDecoder*</tt>: Decoder state. |
| 383 * @param [in] Fs <tt>opus_int32</tt>: Sampling rate to decode to (Hz) |
| 384 * @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode |
| 385 * @retval OPUS_OK Success or @ref opus_errorcodes |
| 386 */ |
| 387 OPUS_EXPORT int opus_decoder_init( |
| 388 OpusDecoder *st, |
| 389 opus_int32 Fs, |
| 390 int channels |
| 391 ) OPUS_ARG_NONNULL(1); |
| 392 |
| 393 /** Decode an Opus frame |
| 394 * @param [in] st <tt>OpusDecoder*</tt>: Decoder state |
| 395 * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indica
te packet loss |
| 396 * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload* |
| 397 * @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 chann
els). length |
| 398 * is frame_size*channels*sizeof(opus_int16) |
| 399 * @param [in] frame_size Number of samples per channel of available space in *
pcm, |
| 400 * if less than the maximum frame size (120ms) some frames can not be decoded |
| 401 * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band
forward error correction data be |
| 402 * decoded. If no such data is available the frame is decoded as if it were lo
st. |
| 403 * @returns Number of decoded samples or @ref opus_errorcodes |
| 404 */ |
| 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 |
| 414 /** Decode an opus frame with floating point output |
| 415 * @param [in] st <tt>OpusDecoder*</tt>: Decoder state |
| 416 * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indica
te packet loss |
| 417 * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload |
| 418 * @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels).
length |
| 419 * is frame_size*channels*sizeof(float) |
| 420 * @param [in] frame_size Number of samples per channel of available space in *
pcm, |
| 421 * if less than the maximum frame size (120ms) some frames can not be decoded |
| 422 * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band
forward error correction data be |
| 423 * decoded. If no such data is available the frame is decoded as if it were lo
st. |
| 424 * @returns Number of decoded samples or @ref opus_errorcodes |
| 425 */ |
| 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 |
| 435 /** Perform a CTL function on an Opus decoder. |
| 436 * |
| 437 * Generally the request and subsequent arguments are generated |
| 438 * by a convenience macro. |
| 439 * @see opus_genericctls |
| 440 */ |
| 441 OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NON
NULL(1); |
| 442 |
| 443 /** Frees an OpusDecoder allocated by opus_decoder_create. |
| 444 * @param[in] st <tt>OpusDecoder*</tt>: State to be freed. |
| 445 */ |
| 446 OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); |
| 447 |
| 448 /** Parse an opus packet into one or more frames. |
| 449 * Opus_decode will perform this operation internally so most applications do |
| 450 * not need to use this function. |
| 451 * This function does not copy the frames, the returned pointers are pointers i
nto |
| 452 * the input packet. |
| 453 * @param [in] data <tt>char*</tt>: Opus packet to be parsed |
| 454 * @param [in] len <tt>opus_int32</tt>: size of data |
| 455 * @param [out] out_toc <tt>char*</tt>: TOC pointer |
| 456 * @param [out] frames <tt>char*[48]</tt> encapsulated frames |
| 457 * @param [out] size <tt>short[48]</tt> sizes of the encapsulated frames |
| 458 * @param [out] payload_offset <tt>int*</tt>: returns the position of the paylo
ad within the packet (in bytes) |
| 459 * @returns number of frames |
| 460 */ |
| 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 |
| 470 /** Gets the bandwidth of an Opus packet. |
| 471 * @param [in] data <tt>char*</tt>: Opus packet |
| 472 * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) |
| 473 * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) |
| 474 * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) |
| 475 * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) |
| 476 * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) |
| 477 * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an
unsupported type |
| 478 */ |
| 479 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned
char *data) OPUS_ARG_NONNULL(1); |
| 480 |
| 481 /** Gets the number of samples per frame from an Opus packet. |
| 482 * @param [in] data <tt>char*</tt>: Opus packet |
| 483 * @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz |
| 484 * @returns Number of samples per frame |
| 485 * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an
unsupported type |
| 486 */ |
| 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 |
| 489 /** Gets the number of channels from an Opus packet. |
| 490 * @param [in] data <tt>char*</tt>: Opus packet |
| 491 * @returns Number of channels |
| 492 * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an
unsupported type |
| 493 */ |
| 494 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsign
ed char *data) OPUS_ARG_NONNULL(1); |
| 495 |
| 496 /** Gets the number of frames in an Opus packet. |
| 497 * @param [in] packet <tt>char*</tt>: Opus packet |
| 498 * @param [in] len <tt>opus_int32</tt>: Length of packet |
| 499 * @returns Number of frames |
| 500 * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an
unsupported type |
| 501 */ |
| 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 |
| 504 /** Gets the number of samples of an Opus packet. |
| 505 * @param [in] dec <tt>OpusDecoder*</tt>: Decoder state |
| 506 * @param [in] packet <tt>char*</tt>: Opus packet |
| 507 * @param [in] len <tt>opus_int32</tt>: Length of packet |
| 508 * @returns Number of samples |
| 509 * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an
unsupported type |
| 510 */ |
| 511 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDe
coder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OP
US_ARG_NONNULL(2); |
| 512 /**@}*/ |
| 513 |
| 514 /** @defgroup opus_repacketizer Repacketizer |
| 515 * @{ |
| 516 * |
| 517 * The repacketizer can be used to merge multiple Opus packets into a single pa
cket |
| 518 * or alternatively to split Opus packets that have previously been merged. |
| 519 * |
| 520 */ |
| 521 |
| 522 typedef struct OpusRepacketizer OpusRepacketizer; |
| 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(v
oid); |
| 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(OpusR
epacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPU
S_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); |
| 535 |
| 536 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepa
cketizer *rp) OPUS_ARG_NONNULL(1); |
| 537 |
| 538 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacke
tizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1); |
| 539 |
| 540 /**@}*/ |
| 541 |
| 542 #ifdef __cplusplus |
| 543 } |
| 544 #endif |
| 545 |
| 546 #endif /* OPUS_H */ |
| OLD | NEW |