opus.h   opus.h 
skipping to change at line 70 skipping to change at line 70
* @li Support for mono and stereo * @li Support for mono and stereo
* @li Support for multichannel (up to 255 channels) * @li Support for multichannel (up to 255 channels)
* @li Frame sizes from 2.5 ms to 60 ms * @li Frame sizes from 2.5 ms to 60 ms
* @li Good loss robustness and packet loss concealment (PLC) * @li Good loss robustness and packet loss concealment (PLC)
* @li Floating point and fixed-point implementation * @li Floating point and fixed-point implementation
* *
* Documentation sections: * Documentation sections:
* @li @ref opus_encoder * @li @ref opus_encoder
* @li @ref opus_decoder * @li @ref opus_decoder
* @li @ref opus_repacketizer * @li @ref opus_repacketizer
* @li @ref opus_multistream
* @li @ref opus_libinfo * @li @ref opus_libinfo
* @li @ref opus_custom * @li @ref opus_custom
*/ */
/** @defgroup opus_encoder Opus Encoder /** @defgroup opus_encoder Opus Encoder
* @{ * @{
* *
* @brief This page describes the process and functions used to encode Opu s. * @brief This page describes the process and functions used to encode Opu s.
* *
* Since Opus is a stateful codec, the encoding process starts with creati ng an encoder * Since Opus is a stateful codec, the encoding process starts with creati ng an encoder
skipping to change at line 138 skipping to change at line 139
* 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: * 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:
* @code * @code
* len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);
* @endcode * @endcode
* *
* where * where
* <ul> * <ul>
* <li>audio_frame is the audio data in opus_int16 (or float for opus_enco de_float())</li> * <li>audio_frame is the audio data in opus_int16 (or float for opus_enco de_float())</li>
* <li>frame_size is the duration of the frame in samples (per channel)</l i> * <li>frame_size is the duration of the frame in samples (per channel)</l i>
* <li>packet is the byte array to which the compressed data is written</l i> * <li>packet is the byte array to which the compressed data is written</l i>
* <li>max_packet is the maximum number of bytes that can be written in th * <li>max_packet is the maximum number of bytes that can be written in th
e packet (4000 bytes is recommended)</li> e packet (4000 bytes is recommended).
* Do not use max_packet to control VBR target bitrate, instead use th
e #OPUS_SET_BITRATE CTL.</li>
* </ul> * </ul>
* *
* opus_encode() and opus_encode_frame() return the number of bytes actual ly written to the packet. * opus_encode() and opus_encode_float() return the number of bytes actual ly written to the packet.
* The return value <b>can be negative</b>, which indicates that an error has occurred. If the return value * The return value <b>can be negative</b>, which indicates that an error has occurred. If the return value
* is 1 byte, then the packet does not need to be transmitted (DTX). * is 1 byte, then the packet does not need to be transmitted (DTX).
* *
* Once the encoder state if no longer needed, it can be destroyed with * Once the encoder state if no longer needed, it can be destroyed with
* *
* @code * @code
* opus_encoder_destroy(enc); * opus_encoder_destroy(enc);
* @endcode * @endcode
* *
* If the encoder was created with opus_encoder_init() rather than opus_en coder_create(), * If the encoder was created with opus_encoder_init() rather than opus_en coder_create(),
skipping to change at line 164 skipping to change at line 166
* *
*/ */
/** Opus encoder state. /** Opus encoder state.
* This contains the complete state of an Opus encoder. * This contains the complete state of an Opus encoder.
* It is position independent and can be freely copied. * It is position independent and can be freely copied.
* @see opus_encoder_create,opus_encoder_init * @see opus_encoder_create,opus_encoder_init
*/ */
typedef struct OpusEncoder OpusEncoder; typedef struct OpusEncoder OpusEncoder;
/** Gets the size of an <code>OpusEncoder</code> structure.
* @param[in] channels <tt>int</tt>: Number of channels.
* This must be 1 or 2.
* @returns The size in bytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels) ; OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels) ;
/** /**
*/ */
/** Allocates and initializes an encoder state. /** Allocates and initializes an encoder state.
* There are three coding modes: * There are three coding modes:
* *
* @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voi ce * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voi ce
* signals. It enhances the input signal by high-pass filtering and * signals. It enhances the input signal by high-pass filtering and
skipping to change at line 191 skipping to change at line 198
* (music/voice) content, broadcast, and applications requiring less * (music/voice) content, broadcast, and applications requiring less
* than 15 ms of coding delay. * than 15 ms of coding delay.
* *
* @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that
* disables the speech-optimized mode in exchange for slightly reduced d elay. * disables the speech-optimized mode in exchange for slightly reduced d elay.
* This mode can only be set on an newly initialized or freshly reset en coder * This mode can only be set on an newly initialized or freshly reset en coder
* because it changes the codec delay. * because it changes the codec delay.
* *
* This is useful when the caller knows that the speech-optimized modes wil l not be needed (use with caution). * This is useful when the caller knows that the speech-optimized modes wil l not be needed (use with caution).
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz) * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
* @param [in] channels <tt>int</tt>: Number of channels (1/2) in input sig * This must be one of 8000, 12000, 160
nal 00,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input
signal
* @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION _VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY ) * @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION _VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY )
* @param [out] error <tt>int*</tt>: @ref opus_errorcodes * @param [out] error <tt>int*</tt>: @ref opus_errorcodes
* @note Regardless of the sampling rate and number channels selected, the Opus encoder * @note Regardless of the sampling rate and number channels selected, the Opus encoder
* can switch to a lower audio audio bandwidth or number of channels if the bitrate * can switch to a lower audio bandwidth or number of channels if the bitra te
* selected is too low. This also means that it is safe to always use 48 kH z stereo input * selected is too low. This also means that it is safe to always use 48 kH z stereo input
* and let the encoder optimize the encoding. * and let the encoder optimize the encoding.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
opus_int32 Fs, opus_int32 Fs,
int channels, int channels,
int application, int application,
int *error int *error
); );
/** Initializes a previously allocated encoder state /** Initializes a previously allocated encoder state
* The memory pointed to by st must be the size returned by opus_encoder_g et_size. * The memory pointed to by st must be at least the size returned by opus_ encoder_get_size().
* This is intended for applications which use their own allocator instead of malloc. * This is intended for applications which use their own allocator instead of malloc.
* @see opus_encoder_create(),opus_encoder_get_size() * @see opus_encoder_create(),opus_encoder_get_size()
* To reset a previously initialized state use the OPUS_RESET_STATE CTL. * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz) * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
* @param [in] channels <tt>int</tt>: Number of channels (1/2) in input si * This must be one of 8000, 12000, 16
gnal 000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input
signal
* @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOI P/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY) * @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOI P/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @retval OPUS_OK Success or @ref opus_errorcodes * @retval #OPUS_OK Success or @ref opus_errorcodes
*/ */
OPUS_EXPORT int opus_encoder_init( OPUS_EXPORT int opus_encoder_init(
OpusEncoder *st, OpusEncoder *st,
opus_int32 Fs, opus_int32 Fs,
int channels, int channels,
int application int application
) OPUS_ARG_NONNULL(1); ) OPUS_ARG_NONNULL(1);
/** Encodes an Opus frame. /** Encodes an Opus frame.
* The passed frame_size must an opus frame size for the encoder's samplin
g rate.
* For example, at 48kHz the permitted values are 120, 240, 480, 960, 1920
, and 2880.
* Passing in a duration of less than 10ms (480 samples at 48kHz) will
* prevent the encoder from using the LPC or hybrid modes.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 ch annels). length is frame_size*channels*sizeof(opus_int16) * @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 ch annels). length is frame_size*channels*sizeof(opus_int16)
* @param [in] frame_size <tt>int</tt>: Number of samples per frame of inp * @param [in] frame_size <tt>int</tt>: Number of samples per channel in t
ut signal he
* @param [out] data <tt>char*</tt>: Output payload (at least max_data_byt * input signal.
es long) * This must be an Opus frame size fo
* @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for pa r
yload; don't use for controlling bitrate * the encoder's sampling rate.
* @returns length of the data payload (in bytes) or @ref opus_errorcodes * For example, at 48 kHz the permitt
ed
* values are 120, 240, 480, 960, 192
0,
* and 2880.
* Passing in a duration of less than
* 10 ms (480 samples at 48 kHz) will
* prevent the encoder from using the
LPC
* or hybrid modes.
* @param [out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage fo
r at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper
limit on
* the instant bitrate, bu
t should
* not be used as the only
bitrate
* control. Use #OPUS_SET_
BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
OpusEncoder *st, OpusEncoder *st,
const opus_int16 *pcm, const opus_int16 *pcm,
int frame_size, int frame_size,
unsigned char *data, unsigned char *data,
opus_int32 max_data_bytes opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Encodes an Opus frame from floating point input. /** Encodes an Opus frame from floating point input.
* The passed frame_size must an opus frame size for the encoder's samplin
g rate.
* For example, at 48kHz the permitted values are 120, 240, 480, 960, 1920
, and 2880.
* Passing in a duration of less than 10ms (480 samples at 48kHz) will
* prevent the encoder from using the LPC or hybrid modes.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] pcm <tt>float*</tt>: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. * @param [in] pcm <tt>float*</tt>: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0.
* Samples with a range beyond +/-1.0 are supported but will * Samples with a range beyond +/-1.0 are supported but will
* be clipped by decoders using the integer API and should * be clipped by decoders using the integer API and should
* only be used if it is known that the far end supports * only be used if it is known that the far end supports
* extended dynamic range. * extended dynamic range.
* length is frame_size*channels*sizeof(float) * length is frame_size*channels*sizeof(float)
* @param [in] frame_size <tt>int</tt>: Number of samples per frame of inp * @param [in] frame_size <tt>int</tt>: Number of samples per channel in t
ut signal he
* @param [out] data <tt>char*</tt>: Output payload (at least max_data_byt * input signal.
es long) * This must be an Opus frame size fo
* @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for pa r
yload; don't use for controlling bitrate * the encoder's sampling rate.
* @returns length of the data payload (in bytes) or @ref opus_errorcodes * For example, at 48 kHz the permitt
ed
* values are 120, 240, 480, 960, 192
0,
* and 2880.
* Passing in a duration of less than
* 10 ms (480 samples at 48 kHz) will
* prevent the encoder from using the
LPC
* or hybrid modes.
* @param [out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage fo
r at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper
limit on
* the instant bitrate, bu
t should
* not be used as the only
bitrate
* control. Use #OPUS_SET_
BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(
OpusEncoder *st, OpusEncoder *st,
const float *pcm, const float *pcm,
int frame_size, int frame_size,
unsigned char *data, unsigned char *data,
opus_int32 max_data_bytes opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Frees an OpusEncoder allocated by opus_encoder_create. /** Frees an <code>OpusEncoder</code> allocated by opus_encoder_create().
* @param[in] st <tt>OpusEncoder*</tt>: State to be freed. * @param[in] st <tt>OpusEncoder*</tt>: State to be freed.
*/ */
OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
/** Perform a CTL function on an Opus encoder. /** Perform a CTL function on an Opus encoder.
* *
* Generally the request and subsequent arguments are generated * Generally the request and subsequent arguments are generated
* by a convenience macro. * by a convenience macro.
* @param st <tt>OpusEncoder*</tt>: Encoder state.
* @param request This and all remaining parameters should be replaced by
one
* of the convenience macros in @ref opus_genericctls or
* @ref opus_encoderctls.
* @see opus_genericctls
* @see opus_encoderctls * @see opus_encoderctls
*/ */
OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_AR G_NONNULL(1); OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_AR G_NONNULL(1);
/**@}*/ /**@}*/
/** @defgroup opus_decoder Opus Decoder /** @defgroup opus_decoder Opus Decoder
* @{ * @{
* *
* @brief This page describes the process and functions used to decode Opu s. * @brief This page describes the process and functions used to decode Opu s.
* *
* The decoding process also starts with creating a decoder * The decoding process also starts with creating a decoder
* state. This can be done with: * state. This can be done with:
* @code * @code
* int error; * int error;
* OpusDecoder *dec; * OpusDecoder *dec;
* dec = opus_decoder_create(Fs, channels, &error); * dec = opus_decoder_create(Fs, channels, &error);
* @endcode * @endcode
* where * where
* @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 4 8000 * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 4 8000
* @li channels is the number of channels (1 or 2) * @li channels is the number of channels (1 or 2)
* @li error will hold the error code in case or failure (or OPUS_OK on su ccess) * @li error will hold the error code in case of failure (or #OPUS_OK on s uccess)
* @li the return value is a newly created decoder state to be used for de coding * @li the return value is a newly created decoder state to be used for de coding
* *
* While opus_decoder_create() allocates memory for the state, it's also p ossible * While opus_decoder_create() allocates memory for the state, it's also p ossible
* to initialize pre-allocated memory: * to initialize pre-allocated memory:
* @code * @code
* int size; * int size;
* int error; * int error;
* OpusDecoder *dec; * OpusDecoder *dec;
* size = opus_decoder_get_size(channels); * size = opus_decoder_get_size(channels);
* dec = malloc(size); * dec = malloc(size);
skipping to change at line 329 skipping to change at line 377
* frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0);
* @endcode * @endcode
* where * where
* *
* @li packet is the byte array containing the compressed data * @li packet is the byte array containing the compressed data
* @li len is the exact number of bytes contained in the packet * @li len is the exact number of bytes contained in the packet
* @li decoded is the decoded audio data in opus_int16 (or float for opus_ decode_float()) * @li decoded is the decoded audio data in opus_int16 (or float for opus_ decode_float())
* @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array
* *
* opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. * opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet.
* If that value is negative, then an error has occured. This can occur if the packet is corrupted or if the audio * If that value is negative, then an error has occurred. This can occur i f the packet is corrupted or if the audio
* buffer is too small to hold the decoded audio. * buffer is too small to hold the decoded audio.
* *
* Opus is a stateful codec with overlapping blocks and as a result Opus * Opus is a stateful codec with overlapping blocks and as a result Opus
* packets are not coded independently of each other. Packets must be * packets are not coded independently of each other. Packets must be
* passed into the decoder serially and in the correct order for a correct * passed into the decoder serially and in the correct order for a correct
* decode. Lost packets can be replaced with loss concealment by calling * decode. Lost packets can be replaced with loss concealment by calling
* the decoder with a null pointer and zero length for the missing packet. * the decoder with a null pointer and zero length for the missing packet.
* *
* A single codec state may only be accessed from a single thread at * A single codec state may only be accessed from a single thread at
* a time and any required locking must be performed by the caller. Separa te * a time and any required locking must be performed by the caller. Separa te
skipping to change at line 353 skipping to change at line 401
* *
*/ */
/** Opus decoder state. /** Opus decoder state.
* This contains the complete state of an Opus decoder. * This contains the complete state of an Opus decoder.
* It is position independent and can be freely copied. * It is position independent and can be freely copied.
* @see opus_decoder_create,opus_decoder_init * @see opus_decoder_create,opus_decoder_init
*/ */
typedef struct OpusDecoder OpusDecoder; typedef struct OpusDecoder OpusDecoder;
/** Gets the size of an OpusDecoder structure. /** Gets the size of an <code>OpusDecoder</code> structure.
* @param [in] channels <tt>int</tt>: Number of channels * @param [in] channels <tt>int</tt>: Number of channels.
* @returns size * This must be 1 or 2.
* @returns The size in bytes.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels) ; OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels) ;
/** Allocates and initializes a decoder state. /** Allocates and initializes a decoder state.
* @param [in] Fs <tt>opus_int32</tt>: Sample rate to decode at (Hz) * @param [in] Fs <tt>opus_int32</tt>: Sample rate to decode at (Hz).
* @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode * This must be one of 8000, 12000, 16
* @param [out] error <tt>int*</tt>: OPUS_OK Success or @ref opus_errorcod 000,
es * 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) to decod
e
* @param [out] error <tt>int*</tt>: #OPUS_OK Success or @ref opus_errorco
des
* *
* Internally Opus stores data at 48000 Hz, so that should be the default * Internally Opus stores data at 48000 Hz, so that should be the default
* value for Fs. However, the decoder can efficiently decode to buffers * value for Fs. However, the decoder can efficiently decode to buffers
* at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use
* data at the full sample rate, or knows the compressed data doesn't * data at the full sample rate, or knows the compressed data doesn't
* use the full frequency range, it can request decoding at a reduced * use the full frequency range, it can request decoding at a reduced
* rate. Likewise, the decoder is capable of filling in either mono or * rate. Likewise, the decoder is capable of filling in either mono or
* interleaved stereo pcm buffers, at the caller's request. * interleaved stereo pcm buffers, at the caller's request.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
opus_int32 Fs, opus_int32 Fs,
int channels, int channels,
int *error int *error
); );
/** Initializes a previously allocated decoder state. /** Initializes a previously allocated decoder state.
* The state must be the size returned by opus_decoder_get_size. * The state must be at least the size returned by opus_decoder_get_size() .
* This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size
* To reset a previously initialized state use the OPUS_RESET_STATE CTL. * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state.
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate to decode to (Hz) * @param [in] Fs <tt>opus_int32</tt>: Sampling rate to decode to (Hz).
* @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode * This must be one of 8000, 12000, 16
* @retval OPUS_OK Success or @ref opus_errorcodes 000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) to decod
e
* @retval #OPUS_OK Success or @ref opus_errorcodes
*/ */
OPUS_EXPORT int opus_decoder_init( OPUS_EXPORT int opus_decoder_init(
OpusDecoder *st, OpusDecoder *st,
opus_int32 Fs, opus_int32 Fs,
int channels int channels
) OPUS_ARG_NONNULL(1); ) OPUS_ARG_NONNULL(1);
/** Decode an Opus frame /** Decode an Opus packet.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to i ndicate packet loss * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to i ndicate packet loss
* @param [in] len <tt>opus_int32</tt>: Number of bytes in payload* * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload*
* @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length * @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
* is frame_size*channels*sizeof(opus_int16) * is frame_size*channels*sizeof(opus_int16)
* @param [in] frame_size Number of samples per channel of available space * @param [in] frame_size Number of samples per channel of available space
in *pcm, in \a pcm.
* if less than the maximum frame size (120ms) some frames can not be dec * If this is less than the maximum packet duration (120ms; 5760 for 48kH
oded z), this function will
* @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in- * not be capable of decoding some packets. In the case of PLC (data==NUL
band forward error correction data be L) or FEC (decode_fec=1),
* decoded. If no such data is available the frame is decoded as if it we * then frame_size needs to be exactly the duration of audio that is miss
re lost. ing, otherwise the
* decoder will not be in the optimal state to decode the next incoming p
acket. For the PLC and
* FEC cases, frame_size <b>must</b> be a multiple of 2.5 ms.
* @param [in] decode_fec <tt>int</tt>: Flag (0 or 1) to request that any
in-band forward error correction data be
* decoded. If no such data is available, the frame is decoded as if it w
ere lost.
* @returns Number of decoded samples or @ref opus_errorcodes * @returns Number of decoded samples or @ref opus_errorcodes
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
OpusDecoder *st, OpusDecoder *st,
const unsigned char *data, const unsigned char *data,
opus_int32 len, opus_int32 len,
opus_int16 *pcm, opus_int16 *pcm,
int frame_size, int frame_size,
int decode_fec int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Decode an opus frame with floating point output /** Decode an Opus packet with floating point output.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to i ndicate packet loss * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to i ndicate packet loss
* @param [in] len <tt>opus_int32</tt>: Number of bytes in payload * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload
* @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 chann els). length * @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 chann els). length
* is frame_size*channels*sizeof(float) * is frame_size*channels*sizeof(float)
* @param [in] frame_size Number of samples per channel of available space * @param [in] frame_size Number of samples per channel of available space
in *pcm, in \a pcm.
* if less than the maximum frame size (120ms) some frames can not be dec * If this is less than the maximum packet duration (120ms; 5760 for 48kH
oded z), this function will
* @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in- * not be capable of decoding some packets. In the case of PLC (data==NUL
band forward error correction data be L) or FEC (decode_fec=1),
* then frame_size needs to be exactly the duration of audio that is miss
ing, otherwise the
* decoder will not be in the optimal state to decode the next incoming p
acket. For the PLC and
* FEC cases, frame_size <b>must</b> be a multiple of 2.5 ms.
* @param [in] decode_fec <tt>int</tt>: Flag (0 or 1) to request that any
in-band forward error correction data be
* decoded. If no such data is available the frame is decoded as if it we re lost. * decoded. If no such data is available the frame is decoded as if it we re lost.
* @returns Number of decoded samples or @ref opus_errorcodes * @returns Number of decoded samples or @ref opus_errorcodes
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
OpusDecoder *st, OpusDecoder *st,
const unsigned char *data, const unsigned char *data,
opus_int32 len, opus_int32 len,
float *pcm, float *pcm,
int frame_size, int frame_size,
int decode_fec int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Perform a CTL function on an Opus decoder. /** Perform a CTL function on an Opus decoder.
* *
* Generally the request and subsequent arguments are generated * Generally the request and subsequent arguments are generated
* by a convenience macro. * by a convenience macro.
* @param st <tt>OpusDecoder*</tt>: Decoder state.
* @param request This and all remaining parameters should be replaced by
one
* of the convenience macros in @ref opus_genericctls or
* @ref opus_decoderctls.
* @see opus_genericctls * @see opus_genericctls
* @see opus_decoderctls
*/ */
OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_AR G_NONNULL(1); OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_AR G_NONNULL(1);
/** Frees an OpusDecoder allocated by opus_decoder_create. /** Frees an <code>OpusDecoder</code> allocated by opus_decoder_create().
* @param[in] st <tt>OpusDecoder*</tt>: State to be freed. * @param[in] st <tt>OpusDecoder*</tt>: State to be freed.
*/ */
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
/** Parse an opus packet into one or more frames. /** Parse an opus packet into one or more frames.
* Opus_decode will perform this operation internally so most applications do * Opus_decode will perform this operation internally so most applications do
* not need to use this function. * not need to use this function.
* This function does not copy the frames, the returned pointers are point ers into * This function does not copy the frames, the returned pointers are point ers into
* the input packet. * the input packet.
* @param [in] data <tt>char*</tt>: Opus packet to be parsed * @param [in] data <tt>char*</tt>: Opus packet to be parsed
skipping to change at line 482 skipping to change at line 548
* @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass)
* @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass)
* @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass)
* @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass)
* @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass)
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const uns igned char *data) OPUS_ARG_NONNULL(1); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const uns igned char *data) OPUS_ARG_NONNULL(1);
/** Gets the number of samples per frame from an Opus packet. /** Gets the number of samples per frame from an Opus packet.
* @param [in] data <tt>char*</tt>: Opus packet * @param [in] data <tt>char*</tt>: Opus packet.
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz * This must contain at least one byte of
* @returns Number of samples per frame * data.
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or * @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz.
of an unsupported type * This must be a multiple of 400, or
* inaccurate results will be returned
.
* @returns Number of samples per frame.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(c onst unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(c onst unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Gets the number of channels from an Opus packet. /** Gets the number of channels from an Opus packet.
* @param [in] data <tt>char*</tt>: Opus packet * @param [in] data <tt>char*</tt>: Opus packet
* @returns Number of channels * @returns Number of channels
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const u nsigned char *data) OPUS_ARG_NONNULL(1); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const u nsigned char *data) OPUS_ARG_NONNULL(1);
/** Gets the number of frames in an Opus packet. /** Gets the number of frames in an Opus packet.
* @param [in] packet <tt>char*</tt>: Opus packet * @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet * @param [in] len <tt>opus_int32</tt>: Length of packet
* @returns Number of frames * @returns Number of frames
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const uns igned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const uns igned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
/** Gets the number of samples of an Opus packet. /** Gets the number of samples of an Opus packet.
* @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz.
* This must be a multiple of 400, or
* inaccurate results will be returned
.
* @returns Number of samples
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or
of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const un
signed char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Gets the number of samples of an Opus packet.
* @param [in] dec <tt>OpusDecoder*</tt>: Decoder state * @param [in] dec <tt>OpusDecoder*</tt>: Decoder state
* @param [in] packet <tt>char*</tt>: Opus packet * @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet * @param [in] len <tt>opus_int32</tt>: Length of packet
* @returns Number of samples * @returns Number of samples
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const O pusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NON NULL(1) OPUS_ARG_NONNULL(2); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const O pusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NON NULL(1) OPUS_ARG_NONNULL(2);
/**@}*/ /**@}*/
/** @defgroup opus_repacketizer Repacketizer /** @defgroup opus_repacketizer Repacketizer
* @{ * @{
* *
* The repacketizer can be used to merge multiple Opus packets into a sing * The repacketizer can be used to merge multiple Opus packets into a sing
le packet le
* or alternatively to split Opus packets that have previously been merged * packet or alternatively to split Opus packets that have previously been
. * merged. Splitting valid Opus packets is always guaranteed to succeed,
* whereas merging valid packets only succeeds if all frames have the same
* mode, bandwidth, and frame size, and when the total duration of the mer
ged
* packet is no more than 120 ms.
* The repacketizer currently only operates on elementary Opus
* streams. It will not manipualte multistream packets successfully, excep
t in
* the degenerate case where they consist of data from a single stream.
*
* The repacketizing process starts with creating a repacketizer state, ei
ther
* by calling opus_repacketizer_create() or by allocating the memory yours
elf,
* e.g.,
* @code
* OpusRepacketizer *rp;
* rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size());
* if (rp != NULL)
* opus_repacketizer_init(rp);
* @endcode
* *
* Then the application should submit packets with opus_repacketizer_cat()
,
* extract new packets with opus_repacketizer_out() or
* opus_repacketizer_out_range(), and then reset the state for the next se
t of
* input packets via opus_repacketizer_init().
*
* For example, to split a sequence of packets into individual frames:
* @code
* unsigned char *data;
* int len;
* while (get_next_packet(&data, &len))
* {
* unsigned char out[1276];
* opus_int32 out_len;
* int nb_frames;
* int err;
* int i;
* err = opus_repacketizer_cat(rp, data, len);
* if (err != OPUS_OK)
* {
* release_packet(data);
* return err;
* }
* nb_frames = opus_repacketizer_get_nb_frames(rp);
* for (i = 0; i < nb_frames; i++)
* {
* out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out))
;
* if (out_len < 0)
* {
* release_packet(data);
* return (int)out_len;
* }
* output_next_packet(out, out_len);
* }
* opus_repacketizer_init(rp);
* release_packet(data);
* }
* @endcode
*
* Alternatively, to combine a sequence of frames into packets that each
* contain up to <code>TARGET_DURATION_MS</code> milliseconds of data:
* @code
* // The maximum number of packets with duration TARGET_DURATION_MS occur
s
* // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/
5)
* // packets.
* unsigned char *data[(TARGET_DURATION_MS*2/5)+1];
* opus_int32 len[(TARGET_DURATION_MS*2/5)+1];
* int nb_packets;
* unsigned char out[1277*(TARGET_DURATION_MS*2/2)];
* opus_int32 out_len;
* int prev_toc;
* nb_packets = 0;
* while (get_next_packet(data+nb_packets, len+nb_packets))
* {
* int nb_frames;
* int err;
* nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packet
s]);
* if (nb_frames < 1)
* {
* release_packets(data, nb_packets+1);
* return nb_frames;
* }
* nb_frames += opus_repacketizer_get_nb_frames(rp);
* // If adding the next packet would exceed our target, or it has an
* // incompatible TOC sequence, output the packets we already have befo
re
* // submitting it.
* // N.B., The nb_packets > 0 check ensures we've submitted at least on
e
* // packet since the last call to opus_repacketizer_init(). Otherwise
a
* // single packet longer than TARGET_DURATION_MS would cause us to try
to
* // output an (invalid) empty packet. It also ensures that prev_toc ha
s
* // been set to a valid value. Additionally, len[nb_packets] > 0 is
* // guaranteed by the call to opus_packet_get_nb_frames() above, so th
e
* // reference to data[nb_packets][0] should be valid.
* if (nb_packets > 0 && (
* ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) ||
* opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_fra
mes >
* TARGET_DURATION_MS*48))
* {
* out_len = opus_repacketizer_out(rp, out, sizeof(out));
* if (out_len < 0)
* {
* release_packets(data, nb_packets+1);
* return (int)out_len;
* }
* output_next_packet(out, out_len);
* opus_repacketizer_init(rp);
* release_packets(data, nb_packets);
* data[0] = data[nb_packets];
* len[0] = len[nb_packets];
* nb_packets = 0;
* }
* err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]);
* if (err != OPUS_OK)
* {
* release_packets(data, nb_packets+1);
* return err;
* }
* prev_toc = data[nb_packets][0];
* nb_packets++;
* }
* // Output the final, partial packet.
* if (nb_packets > 0)
* {
* out_len = opus_repacketizer_out(rp, out, sizeof(out));
* release_packets(data, nb_packets);
* if (out_len < 0)
* return (int)out_len;
* output_next_packet(out, out_len);
* }
* @endcode
*
* An alternate way of merging packets is to simply call opus_repacketizer
_cat()
* unconditionally until it fails. At that point, the merged packet can be
* obtained with opus_repacketizer_out() and the input packet for which
* opus_repacketizer_cat() needs to be re-added to a newly reinitialized
* repacketizer state.
*/ */
typedef struct OpusRepacketizer OpusRepacketizer; typedef struct OpusRepacketizer OpusRepacketizer;
/** Gets the size of an <code>OpusRepacketizer</code> structure.
* @returns The size in bytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
/** (Re)initializes a previously allocated repacketizer state.
* The state must be at least the size returned by opus_repacketizer_get_s
ize().
* This can be used for applications which use their own allocator instead
of
* malloc().
* It must also be called to reset the queue of packets waiting to be
* repacketized, which is necessary if the maximum packet duration of 120
ms
* is reached or if you wish to submit packets with a different Opus
* configuration (coding mode, audio bandwidth, frame size, or channel cou
nt).
* Failure to do so will prevent a new packet from being added with
* opus_repacketizer_cat().
* @see opus_repacketizer_create
* @see opus_repacketizer_get_size
* @see opus_repacketizer_cat
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state to
* (re)initialize.
* @returns A pointer to the same repacketizer state that was passed in.
*/
OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
/** Allocates memory and initializes the new repacketizer with
* opus_repacketizer_init().
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_cre ate(void); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_cre ate(void);
/** Frees an <code>OpusRepacketizer</code> allocated by
* opus_repacketizer_create().
* @param[in] rp <tt>OpusRepacketizer*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp); OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
/** Add a packet to the current repacketizer state.
* This packet must match the configuration of any packets already submitt
ed
* for repacketization since the last call to opus_repacketizer_init().
* This means that it must have the same coding mode, audio bandwidth, fra
me
* size, and channel count.
* This can be checked in advance by examining the top 6 bits of the first
* byte of the packet, and ensuring they match the top 6 bits of the first
* byte of any previously submitted packet.
* The total duration of audio in the repacketizer state also must not exc
eed
* 120 ms, the maximum duration of a single packet, after adding this pack
et.
*
* The contents of the current repacketizer state can be extracted into ne
w
* packets using opus_repacketizer_out() or opus_repacketizer_out_range().
*
* In order to add a packet with a different configuration or to add more
* audio beyond 120 ms, you must clear the repacketizer state by calling
* opus_repacketizer_init().
* If a packet is too large to add to the current repacketizer state, no p
art
* of it is added, even if it contains multiple frames, some of which migh
t
* fit.
* If you wish to be able to add parts of such packets, you should first u
se
* another repacketizer to split the packet into pieces and add them
* individually.
* @see opus_repacketizer_out_range
* @see opus_repacketizer_out
* @see opus_repacketizer_init
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state to which t
o
* add the packet.
* @param[in] data <tt>const unsigned char*</tt>: The packet data.
* The application must ens
ure
* this pointer remains val
id
* until the next call to
* opus_repacketizer_init()
or
* opus_repacketizer_destro
y().
* @param len <tt>opus_int32</tt>: The number of bytes in the packet data.
* @returns An error code indicating whether or not the operation succeede
d.
* @retval #OPUS_OK The packet's contents have been added to the repacketi
zer
* state.
* @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequen
ce,
* the packet's TOC sequence was not compatib
le
* with previously submitted packets (because
* the coding mode, audio bandwidth, frame si
ze,
* or channel count did not match), or adding
* this packet would increase the total amoun
t of
* audio stored in the repacketizer state to
more
* than 120 ms.
*/
OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
/** Construct a new packet from data previously submitted to the repacketiz
er
* state via opus_repacketizer_cat().
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state from which
to
* construct the new packet.
* @param begin <tt>int</tt>: The index of the first frame in the current
* repacketizer state to include in the output.
* @param end <tt>int</tt>: One past the index of the last frame in the
* current repacketizer state to include in the
* output.
* @param[out] data <tt>const unsigned char*</tt>: The buffer in which to
* store the output packet
.
* @param maxlen <tt>opus_int32</tt>: The maximum number of bytes to store
in
* the output buffer. In order to guara
ntee
* success, this should be at least
* <code>1276</code> for a single frame
,
* or for multiple frames,
* <code>1277*(end-begin)</code>.
* However, <code>1*(end-begin)</code>
plus
* the size of all packet data submitte
d to
* the repacketizer since the last call
to
* opus_repacketizer_init() or
* opus_repacketizer_create() is also
* sufficient, and possibly much smalle
r.
* @returns The total size of the output packet on success, or an error co
de
* on failure.
* @retval #OPUS_BAD_ARG <code>[begin,end)</code> was an invalid range of
* frames (begin < 0, begin >= end, or end >
* opus_repacketizer_get_nb_frames()).
* @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain th
e
* complete output packet.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range( OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 m axlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range( OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 m axlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Return the total number of frames contained in packet data submitted to
* the repacketizer state so far via opus_repacketizer_cat() since the las
t
* call to opus_repacketizer_init() or opus_repacketizer_create().
* This defines the valid range of packets that can be extracted with
* opus_repacketizer_out_range() or opus_repacketizer_out().
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state containing
the
* frames.
* @returns The total number of frames contained in the packet data submit
ted
* to the repacketizer state.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(Opu sRepacketizer *rp) OPUS_ARG_NONNULL(1); OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(Opu sRepacketizer *rp) OPUS_ARG_NONNULL(1);
/** Construct a new packet from data previously submitted to the repacketiz
er
* state via opus_repacketizer_cat().
* This is a convenience routine that returns all the data submitted so fa
r
* in a single packet.
* It is equivalent to calling
* @code
* opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp),
* data, maxlen)
* @endcode
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state from which
to
* construct the new packet.
* @param[out] data <tt>const unsigned char*</tt>: The buffer in which to
* store the output packet
.
* @param maxlen <tt>opus_int32</tt>: The maximum number of bytes to store
in
* the output buffer. In order to guara
ntee
* success, this should be at least
* <code>1277*opus_repacketizer_get_nb_
frames(rp)</code>.
* However,
* <code>1*opus_repacketizer_get_nb_fra
mes(rp)</code>
* plus the size of all packet data
* submitted to the repacketizer since
the
* last call to opus_repacketizer_init(
) or
* opus_repacketizer_create() is also
* sufficient, and possibly much smalle
r.
* @returns The total size of the output packet on success, or an error co
de
* on failure.
* @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain th
e
* complete output packet.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRe packetizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) ; OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRe packetizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) ;
/**@}*/ /**@}*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* OPUS_H */ #endif /* OPUS_H */
 End of changes. 42 change blocks. 
78 lines changed or deleted 531 lines changed or added


 opus_defines.h   opus_defines.h 
skipping to change at line 66 skipping to change at line 66
#define OPUS_UNIMPLEMENTED -5 #define OPUS_UNIMPLEMENTED -5
/** An encoder or decoder structure is invalid or already freed @hideinitia lizer*/ /** An encoder or decoder structure is invalid or already freed @hideinitia lizer*/
#define OPUS_INVALID_STATE -6 #define OPUS_INVALID_STATE -6
/** Memory allocation has failed @hideinitializer*/ /** Memory allocation has failed @hideinitializer*/
#define OPUS_ALLOC_FAIL -7 #define OPUS_ALLOC_FAIL -7
/**@}*/ /**@}*/
/** @cond OPUS_INTERNAL_DOC */ /** @cond OPUS_INTERNAL_DOC */
/**Export control for opus functions */ /**Export control for opus functions */
#if defined(__GNUC__) && defined(OPUS_BUILD) #ifndef OPUS_EXPORT
# define OPUS_EXPORT __attribute__ ((visibility ("default"))) # if defined(__GNUC__) && defined(OPUS_BUILD)
#elif defined(WIN32) && !defined(__MINGW32__) # define OPUS_EXPORT __attribute__ ((visibility ("default")))
# ifdef OPUS_BUILD # elif defined(WIN32) && !defined(__MINGW32__)
# ifdef OPUS_BUILD
# define OPUS_EXPORT __declspec(dllexport) # define OPUS_EXPORT __declspec(dllexport)
# else # else
# define OPUS_EXPORT # define OPUS_EXPORT
# endif
# else
# define OPUS_EXPORT
# endif # endif
#else
# define OPUS_EXPORT
#endif #endif
# if !defined(OPUS_GNUC_PREREQ) # if !defined(OPUS_GNUC_PREREQ)
# if defined(__GNUC__)&&defined(__GNUC_MINOR__) # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
# define OPUS_GNUC_PREREQ(_maj,_min) \ # define OPUS_GNUC_PREREQ(_maj,_min) \
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
# else # else
# define OPUS_GNUC_PREREQ(_maj,_min) 0 # define OPUS_GNUC_PREREQ(_maj,_min) 0
# endif # endif
# endif # endif
skipping to change at line 146 skipping to change at line 148
#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 #define OPUS_SET_FORCE_CHANNELS_REQUEST 4022
#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 #define OPUS_GET_FORCE_CHANNELS_REQUEST 4023
#define OPUS_SET_SIGNAL_REQUEST 4024 #define OPUS_SET_SIGNAL_REQUEST 4024
#define OPUS_GET_SIGNAL_REQUEST 4025 #define OPUS_GET_SIGNAL_REQUEST 4025
#define OPUS_GET_LOOKAHEAD_REQUEST 4027 #define OPUS_GET_LOOKAHEAD_REQUEST 4027
/* #define OPUS_RESET_STATE 4028 */ /* #define OPUS_RESET_STATE 4028 */
#define OPUS_GET_SAMPLE_RATE_REQUEST 4029 #define OPUS_GET_SAMPLE_RATE_REQUEST 4029
#define OPUS_GET_FINAL_RANGE_REQUEST 4031 #define OPUS_GET_FINAL_RANGE_REQUEST 4031
#define OPUS_GET_PITCH_REQUEST 4033 #define OPUS_GET_PITCH_REQUEST 4033
#define OPUS_SET_GAIN_REQUEST 4034 #define OPUS_SET_GAIN_REQUEST 4034
#define OPUS_GET_GAIN_REQUEST 4045 #define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */
#define OPUS_SET_LSB_DEPTH_REQUEST 4036 #define OPUS_SET_LSB_DEPTH_REQUEST 4036
#define OPUS_GET_LSB_DEPTH_REQUEST 4037 #define OPUS_GET_LSB_DEPTH_REQUEST 4037
#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039
/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
/* Macros to trigger compilation errors when the wrong types are provided t o a CTL */ /* Macros to trigger compilation errors when the wrong types are provided t o a CTL */
#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x )) #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x ))
#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
/** @endcond */ /** @endcond */
/** @defgroup opus_ctlvalues Pre-defined values for CTL interface /** @defgroup opus_ctlvalues Pre-defined values for CTL interface
* @see opus_genericctls, opus_encoderctls * @see opus_genericctls, opus_encoderctls
* @{ * @{
*/ */
skipping to change at line 502 skipping to change at line 508
#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
/** Gets encoder's configured use of discontinuous transmission. /** Gets encoder's configured use of discontinuous transmission.
* @see OPUS_SET_DTX * @see OPUS_SET_DTX
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following value s: * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following value s:
* <dl> * <dl>
* <dt>0</dt><dd>DTX disabled (default).</dd> * <dt>0</dt><dd>DTX disabled (default).</dd>
* <dt>1</dt><dd>DTX enabled.</dd> * <dt>1</dt><dd>DTX enabled.</dd>
* </dl> * </dl>
* @hideinitializer */ * @hideinitializer */
#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
/** Configures the depth of signal being encoded.
* This is a hint which helps the encoder identify silence and near-silenc
e.
* @see OPUS_GET_LSB_DEPTH
* @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 an
d 24
* (default: 24).
* @hideinitializer */
#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(
x)
/** Gets the encoder's configured signal depth.
* @see OPUS_SET_LSB_DEPTH
* @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8
and
* 24 (default: 24).
* @hideinitializer */
#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_
ptr(x)
/** Gets the duration (in samples) of the last packet successfully decoded
or concealed.
* @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current samp
ling rate).
* @hideinitializer */
#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQU
EST, __opus_check_int_ptr(x)
/**@}*/ /**@}*/
/** @defgroup opus_genericctls Generic CTLs /** @defgroup opus_genericctls Generic CTLs
* *
* These macros are used with the \c opus_decoder_ctl and * These macros are used with the \c opus_decoder_ctl and
* \c opus_encoder_ctl calls to generate a particular * \c opus_encoder_ctl calls to generate a particular
* request. * request.
* *
* When called on an \c OpusDecoder they apply to that * When called on an \c OpusDecoder they apply to that
* particular decoder instance. When called on an * particular decoder instance. When called on an
skipping to change at line 581 skipping to change at line 605
* <dt>#OPUS_AUTO</dt> <dd>(default)</dd> * <dt>#OPUS_AUTO</dt> <dd>(default)</dd>
* <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd> * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd> * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd> * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd> * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd> * <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd>
* </dl> * </dl>
* @hideinitializer */ * @hideinitializer */
#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ ptr(x) #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ ptr(x)
/** Configures the depth of signal being encoded.
* This is a hint which helps the encoder identify silence and near-silenc
e.
* @see OPUS_GET_LSB_DEPTH
* @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 an
d 24
* (default: 24).
* @hideinitializer */
#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(
x)
/** Gets the encoder's configured signal depth.
* @see OPUS_SET_LSB_DEPTH
* @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8
and
* 24 (default: 24).
* @hideinitializer */
#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_
ptr(x)
/**@}*/ /**@}*/
/** @defgroup opus_decoderctls Decoder related CTLs /** @defgroup opus_decoderctls Decoder related CTLs
* @see opus_genericctls, opus_encoderctls, opus_decoder * @see opus_genericctls, opus_encoderctls, opus_decoder
* @{ * @{
*/ */
/** Configures decoder gain adjustment. /** Configures decoder gain adjustment.
* Scales the decoded output by a factor specified in Q8 dB units. * Scales the decoded output by a factor specified in Q8 dB units.
* This has a maximum range of -32768 to 32767 inclusive, and returns * This has a maximum range of -32768 to 32767 inclusive, and returns
 End of changes. 8 change blocks. 
26 lines changed or deleted 40 lines changed or added


 opus_multistream.h   opus_multistream.h 
skipping to change at line 42 skipping to change at line 42
#ifndef OPUS_MULTISTREAM_H #ifndef OPUS_MULTISTREAM_H
#define OPUS_MULTISTREAM_H #define OPUS_MULTISTREAM_H
#include "opus.h" #include "opus.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct OpusMSEncoder OpusMSEncoder; /** @cond OPUS_INTERNAL_DOC */
typedef struct OpusMSDecoder OpusMSDecoder;
/** Macros to trigger compilation errors when the wrong types are provided
to a
* CTL. */
/**@{*/
#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(pt r))) #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(pt r)))
#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(pt r))) #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(pt r)))
/**@}*/
/** These are the actual encoder and decoder CTL ID numbers.
* They should not be used directly by applications.
* In general, SETs should be even and GETs should be odd.*/
/**@{*/
#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
/**@}*/
/** @endcond */
/** @defgroup opus_multistream_ctls Multistream specific encoder and decode
r CTLs
*
* These are convenience macros that are specific to the
* opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl()
* interface.
* The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and
* @ref opus_decoderctls may be applied to a multistream encoder or decode
r as
* well.
* In addition, you may retrieve the encoder or decoder state for an speci
fic
* stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or
* #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
*/
/**@{*/
/** Gets the encoder state for an individual stream of a multistream encode
r.
* @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder
you
* wish to retrieve.
* This must be non-negative and less th
an
* the <code>streams</code> parameter us
ed
* to initialize the encoder.
* @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given
* encoder state.
* @retval OPUS_BAD_ARG The index of the requested stream was out of range
.
* @hideinitializer
*/
#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODE R_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODE R_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
/** Gets the decoder state for an individual stream of a multistream decode
r.
* @param[in] x <tt>opus_int32</tt>: The index of the stream whose decoder
you
* wish to retrieve.
* This must be non-negative and less th
an
* the <code>streams</code> parameter us
ed
* to initialize the decoder.
* @param[out] y <tt>OpusDecoder**</tt>: Returns a pointer to the given
* decoder state.
* @retval OPUS_BAD_ARG The index of the requested stream was out of range
.
* @hideinitializer
*/
#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODE R_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODE R_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
/** Allocate and initialize a multistream encoder state object. /**@}*/
* Call opus_multistream_encoder_destroy() to release
* this object when finished. */ /** @defgroup opus_multistream Opus Multistream API
* @{
*
* The multistream API allows individual Opus streams to be combined into
a
* single packet, enabling support for up to 255 channels. Unlike an
* elementary Opus stream, the encoder and decoder must negotiate the chan
nel
* configuration before the decoder can successfully interpret the data in
the
* packets produced by the encoder. Some basic information, such as packet
* duration, can be computed without any special negotiation.
*
* The format for multistream Opus packets is defined in the
* <a href="http://tools.ietf.org/html/draft-terriberry-oggopus">Ogg
* encapsulation specification</a> and is based on the self-delimited Opus
* framing described in Appendix B of <a href="http://tools.ietf.org/html/
rfc6716">RFC 6716</a>.
* Normal Opus packets are just a degenerate case of multistream Opus pack
ets,
* and can be encoded or decoded with the multistream API by setting
* <code>streams</code> to <code>1</code> when initializing the encoder or
* decoder.
*
* Multistream Opus streams can contain up to 255 elementary Opus streams.
* These may be either "uncoupled" or "coupled", indicating that the decod
er
* is configured to decode them to either 1 or 2 channels, respectively.
* The streams are ordered so that all coupled streams appear at the
* beginning.
*
* A <code>mapping</code> table defines which decoded channel <code>i</cod
e>
* should be used for each input/output (I/O) channel <code>j</code>. This
table is
* typically provided as an unsigned char array.
* Let <code>i = mapping[j]</code> be the index for I/O channel <code>j</c
ode>.
* If <code>i < 2*coupled_streams</code>, then I/O channel <code>j</code>
is
* encoded as the left channel of stream <code>(i/2)</code> if <code>i</co
de>
* is even, or as the right channel of stream <code>(i/2)</code> if
* <code>i</code> is odd. Otherwise, I/O channel <code>j</code> is encoded
as
* mono in stream <code>(i - coupled_streams)</code>, unless it has the sp
ecial
* value 255, in which case it is omitted from the encoding entirely (the
* decoder will reproduce it as silence). Each value <code>i</code> must e
ither
* be the special value 255 or be less than <code>streams + coupled_stream
s</code>.
*
* The output channels specified by the encoder
* should use the
* <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.
9">Vorbis
* channel ordering</a>. A decoder may wish to apply an additional permuta
tion
* to the mapping the encoder used to achieve a different output channel
* order (e.g. for outputing in WAV order).
*
* Each multistream packet contains an Opus packet for each stream, and al
l of
* the Opus packets in a single multistream packet must have the same
* duration. Therefore the duration of a multistream packet can be extract
ed
* from the TOC sequence of the first stream, which is located at the
* beginning of the packet, just like an elementary Opus stream:
*
* @code
* int nb_samples;
* int nb_frames;
* nb_frames = opus_packet_get_nb_frames(data, len);
* if (nb_frames < 1)
* return nb_frames;
* nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames
;
* @endcode
*
* The general encoding and decoding process proceeds exactly the same as
in
* the normal @ref opus_encoder and @ref opus_decoder APIs.
* See their documentation for an overview of how to use the corresponding
* multistream functions.
*/
/** Opus multistream encoder state.
* This contains the complete state of a multistream Opus encoder.
* It is position independent and can be freely copied.
* @see opus_multistream_encoder_create
* @see opus_multistream_encoder_init
*/
typedef struct OpusMSEncoder OpusMSEncoder;
/** Opus multistream decoder state.
* This contains the complete state of a multistream Opus decoder.
* It is position independent and can be freely copied.
* @see opus_multistream_decoder_create
* @see opus_multistream_decoder_init
*/
typedef struct OpusMSDecoder OpusMSDecoder;
/**\name Multistream encoder functions */
/**@{*/
/** Gets the size of an OpusMSEncoder structure.
* @param streams <tt>int</tt>: The total number of streams to encode from
the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) stre
ams
* to encode.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @returns The size in bytes on success, or a negative error code
* (see @ref opus_errorcodes) on error.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get
_size(
int streams,
int coupled_streams
);
/** Allocates and initializes a multistream encoder state.
* Call opus_multistream_encoder_destroy() to release
* this object when finished.
* @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz
).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels in the input signal.
* This must be at most 255.
* It may be greater than the number of
* coded channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams to encode from
the
* input.
* This must be no more than the number of ch
annels.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) stre
ams
* to encode.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than the number of input chan
nels.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping
from
* encoded channels to input channels, as described in
* @ref opus_multistream. As an extra constraint, the
* multistream encoder does not allow encoding coupled
* streams for which one channel is unused since this
* is never a good idea.
* @param application <tt>int</tt>: The target encoder application.
* This must be one of the following:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain mo
des
* of operation.</dd>
* </dl>
* @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an er
ror
* code (see @ref opus_errorcodes) on
* failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder _create( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder _create(
opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ opus_int32 Fs,
int channels, /**< Number of channels in the input signal int channels,
*/ int streams,
int streams, /**< Total number of streams to encode from int coupled_streams,
the input */ const unsigned char *mapping,
int coupled_streams, /**< Number of coupled (stereo) streams to int application,
encode */ int *error
const unsigned char *mapping, /**< Encoded mapping between channels a
nd streams */
int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPU
S_APPLICATION_AUDIO) */
int *error /**< Error code */
) OPUS_ARG_NONNULL(5); ) OPUS_ARG_NONNULL(5);
/** Initialize an already allocated multistream encoder state. */ /** Initialize a previously allocated multistream encoder state.
* The memory pointed to by \a st must be at least the size returned by
* opus_multistream_encoder_get_size().
* This is intended for applications which use their own allocator instead
of
* malloc.
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @see opus_multistream_encoder_create
* @see opus_multistream_encoder_get_size
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initial
ize.
* @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz
).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels in the input signal.
* This must be at most 255.
* It may be greater than the number of
* coded channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams to encode from
the
* input.
* This must be no more than the number of ch
annels.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) stre
ams
* to encode.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than the number of input chan
nels.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping
from
* encoded channels to input channels, as described in
* @ref opus_multistream. As an extra constraint, the
* multistream encoder does not allow encoding coupled
* streams for which one channel is unused since this
* is never a good idea.
* @param application <tt>int</tt>: The target encoder application.
* This must be one of the following:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain mo
des
* of operation.</dd>
* </dl>
* @returns #OPUS_OK on success, or an error code (see @ref opus_errorcode
s)
* on failure.
*/
OPUS_EXPORT int opus_multistream_encoder_init( OPUS_EXPORT int opus_multistream_encoder_init(
OpusMSEncoder *st, /**< Encoder state */ OpusMSEncoder *st,
opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ opus_int32 Fs,
int channels, /**< Number of channels in the input signal int channels,
*/ int streams,
int streams, /**< Total number of streams to encode from int coupled_streams,
the input */ const unsigned char *mapping,
int coupled_streams, /**< Number of coupled (stereo) streams to int application
encode */
const unsigned char *mapping, /**< Encoded mapping between channels a
nd streams */
int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPU
S_APPLICATION_AUDIO) */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
/** Returns length of the data payload (in bytes) or a negative error code /** Encodes a multistream Opus frame.
*/ * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interlea
ved
* samples.
* This must contain
* <code>frame_size*channels</c
ode>
* samples.
* @param frame_size <tt>int</tt>: Number of samples per channel in the in
put
* signal.
* This must be an Opus frame size for the
* encoder's sampling rate.
* For example, at 48 kHz the permitted va
lues
* are 120, 240, 480, 960, 1920, and 2880.
* Passing in a duration of less than 10 m
s
* (480 samples at 48 kHz) will prevent th
e
* encoder from using the LPC or hybrid mo
des.
* @param[out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for
at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper
limit on
* the instant bitrate, bu
t should
* not be used as the only
bitrate
* control. Use #OPUS_SET_
BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
OpusMSEncoder *st, /**< Encoder state */ OpusMSEncoder *st,
const opus_int16 *pcm, /**< Input signal as interleaved samples. L const opus_int16 *pcm,
ength is frame_size*channels */ int frame_size,
int frame_size, /**< Number of samples per frame of input s unsigned char *data,
ignal */ opus_int32 max_data_bytes
unsigned char *data, /**< Output buffer for the compressed paylo
ad (no more than max_data_bytes long) */
opus_int32 max_data_bytes /**< Allocated memory for payload; don't us
e for controlling bitrate */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Returns length of the data payload (in bytes) or a negative error code. /** Encodes a multistream Opus frame from floating point input.
*/ * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
* samples with a normal range of
* +/-1.0.
* Samples with a range beyond +/-1.
0
* are supported but will be clipped
by
* decoders using the integer API an
d
* should only be used if it is know
n
* that the far end supports extende
d
* dynamic range.
* This must contain
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: Number of samples per channel in the in
put
* signal.
* This must be an Opus frame size for the
* encoder's sampling rate.
* For example, at 48 kHz the permitted va
lues
* are 120, 240, 480, 960, 1920, and 2880.
* Passing in a duration of less than 10 m
s
* (480 samples at 48 kHz) will prevent th
e
* encoder from using the LPC or hybrid mo
des.
* @param[out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for
at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper
limit on
* the instant bitrate, bu
t should
* not be used as the only
bitrate
* control. Use #OPUS_SET_
BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
OpusMSEncoder *st, /**< Encoder state */ OpusMSEncoder *st,
const float *pcm, /**< Input signal interleaved in channel or const float *pcm,
der. length is frame_size*channels */ int frame_size,
int frame_size, /**< Number of samples per frame of input s unsigned char *data,
ignal */ opus_int32 max_data_bytes
unsigned char *data, /**< Output buffer for the compressed paylo
ad (no more than max_data_bytes long) */
opus_int32 max_data_bytes /**< Allocated memory for payload; don't us
e for controlling bitrate */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Gets the size of an OpusMSEncoder structure. /** Frees an <code>OpusMSEncoder</code> allocated by
* @returns size * opus_multistream_encoder_create().
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be free
d.
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get
_size(
int streams, /**< Total number of coded streams */
int coupled_streams /**< Number of coupled (stereo) streams */
);
/** Deallocate a multstream encoder state */
OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
/** Get or set options on a multistream encoder state */ /** Perform a CTL function on a multistream Opus encoder.
*
* Generally the request and subsequent arguments are generated by a
* convenience macro.
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param request This and all remaining parameters should be replaced by
one
* of the convenience macros in @ref opus_genericctls,
* @ref opus_encoderctls, or @ref opus_multistream_ctls.
* @see opus_genericctls
* @see opus_encoderctls
* @see opus_multistream_ctls
*/
OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request , ...) OPUS_ARG_NONNULL(1); OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request , ...) OPUS_ARG_NONNULL(1);
/** Allocate and initialize a multistream decoder state object. /**@}*/
* Call opus_multistream_decoder_destroy() to release
* this object when finished. */ /**\name Multistream decoder functions */
/**@{*/
/** Gets the size of an <code>OpusMSDecoder</code> structure.
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number streams to decode as couple
d
* (2 channel) streams.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @returns The size in bytes on success, or a negative error code
* (see @ref opus_errorcodes) on error.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get
_size(
int streams,
int coupled_streams
);
/** Allocates and initializes a multistream decoder state.
* Call opus_multistream_decoder_destroy() to release
* this object when finished.
* @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels to output.
* This must be at most 255.
* It may be different from the number of co
ded
* channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of streams to decode as cou
pled
* (2 channel) streams.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping
from
* coded channels to output channels, as described in
* @ref opus_multistream.
* @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an er
ror
* code (see @ref opus_errorcodes) on
* failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder _create( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder _create(
opus_int32 Fs, /**< Sampling rate to decode at (Hz) */ opus_int32 Fs,
int channels, /**< Number of channels to decode */ int channels,
int streams, /**< Total number of coded streams in the m int streams,
ultistream */ int coupled_streams,
int coupled_streams, /**< Number of coupled (stereo) streams in const unsigned char *mapping,
the multistream */ int *error
const unsigned char *mapping, /**< Stream to channel mapping table */
int *error /**< Error code */
) OPUS_ARG_NONNULL(5); ) OPUS_ARG_NONNULL(5);
/** Intialize a previously allocated decoder state object. */ /** Intialize a previously allocated decoder state object.
* The memory pointed to by \a st must be at least the size returned by
* opus_multistream_encoder_get_size().
* This is intended for applications which use their own allocator instead
of
* malloc.
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @see opus_multistream_decoder_create
* @see opus_multistream_deocder_get_size
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initial
ize.
* @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels to output.
* This must be at most 255.
* It may be different from the number of co
ded
* channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of streams to decode as cou
pled
* (2 channel) streams.
* This must be no larger than the to
tal
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping
from
* coded channels to output channels, as described in
* @ref opus_multistream.
* @returns #OPUS_OK on success, or an error code (see @ref opus_errorcode
s)
* on failure.
*/
OPUS_EXPORT int opus_multistream_decoder_init( OPUS_EXPORT int opus_multistream_decoder_init(
OpusMSDecoder *st, /**< Encoder state */ OpusMSDecoder *st,
opus_int32 Fs, /**< Sample rate of input signal (Hz) */ opus_int32 Fs,
int channels, /**< Number of channels in the input signal int channels,
*/ int streams,
int streams, /**< Total number of coded streams */ int coupled_streams,
int coupled_streams, /**< Number of coupled (stereo) streams */ const unsigned char *mapping
const unsigned char *mapping /**< Stream to channel mapping table */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
/** Returns the number of samples decoded or a negative error code */ /** Decode a multistream Opus packet.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param[in] data <tt>const unsigned char*</tt>: Input payload.
* Use a <code>NULL</code>
* pointer to indicate pack
et
* loss.
* @param len <tt>opus_int32</tt>: Number of bytes in payload.
* @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
* samples.
* This must contain room for
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: The number of samples per channel of
* available space in \a pcm.
* If this is less than the maximum packet
duration
* (120 ms; 5760 for 48kHz), this function
will not be capable
* of decoding some packets. In the case o
f PLC (data==NULL)
* or FEC (decode_fec=1), then frame_size
needs to be exactly
* the duration of audio that is missing,
otherwise the
* decoder will not be in the optimal stat
e to decode the
* next incoming packet. For the PLC and F
EC cases, frame_size
* <b>must</b> be a multiple of 2.5 ms.
* @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-ba
nd
* forward error correction data be decode
d.
* If no such data is available, the frame
is
* decoded as if it were lost.
* @returns Number of samples decoded on success or a negative error code
* (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
OpusMSDecoder *st, /**< Decoder state */ OpusMSDecoder *st,
const unsigned char *data, /**< Input payload. Use a NULL pointer to i const unsigned char *data,
ndicate packet loss */ opus_int32 len,
opus_int32 len, /**< Number of bytes in payload */ opus_int16 *pcm,
opus_int16 *pcm, /**< Output signal, samples interleaved in int frame_size,
channel order . length is frame_size*channels */ int decode_fec
int frame_size, /**< Number of samples per frame of input s
ignal */
int decode_fec /**< Flag (0/1) to request that any in-band
forward error correction data be */
/**< decoded. If no such data is available
the frame is decoded as if it were lost. */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Returns the number of samples decoded or a negative error code */ /** Decode a multistream Opus packet with floating point output.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param[in] data <tt>const unsigned char*</tt>: Input payload.
* Use a <code>NULL</code>
* pointer to indicate pack
et
* loss.
* @param len <tt>opus_int32</tt>: Number of bytes in payload.
* @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
* samples.
* This must contain room for
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: The number of samples per channel of
* available space in \a pcm.
* If this is less than the maximum packet
duration
* (120 ms; 5760 for 48kHz), this function
will not be capable
* of decoding some packets. In the case o
f PLC (data==NULL)
* or FEC (decode_fec=1), then frame_size
needs to be exactly
* the duration of audio that is missing,
otherwise the
* decoder will not be in the optimal stat
e to decode the
* next incoming packet. For the PLC and F
EC cases, frame_size
* <b>must</b> be a multiple of 2.5 ms.
* @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-ba
nd
* forward error correction data be decode
d.
* If no such data is available, the frame
is
* decoded as if it were lost.
* @returns Number of samples decoded on success or a negative error code
* (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
OpusMSDecoder *st, /**< Decoder state */ OpusMSDecoder *st,
const unsigned char *data, /**< Input payload buffer. Use a NULL point const unsigned char *data,
er to indicate packet loss */ opus_int32 len,
opus_int32 len, /**< Number of payload bytes in data */ float *pcm,
float *pcm, /**< Buffer for the output signal (interlea int frame_size,
ved iin channel order). length is frame_size*channels */ int decode_fec
int frame_size, /**< Number of samples per frame of input s
ignal */
int decode_fec /**< Flag (0/1) to request that any in-band
forward error correction data be */
/**< decoded. If no such data is available
the frame is decoded as if it were lost. */
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Gets the size of an OpusMSDecoder structure. /** Perform a CTL function on a multistream Opus decoder.
* @returns size *
* Generally the request and subsequent arguments are generated by a
* convenience macro.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param request This and all remaining parameters should be replaced by
one
* of the convenience macros in @ref opus_genericctls,
* @ref opus_decoderctls, or @ref opus_multistream_ctls.
* @see opus_genericctls
* @see opus_decoderctls
* @see opus_multistream_ctls
*/ */
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get
_size(
int streams, /**< Total number of coded streams */
int coupled_streams /**< Number of coupled (stereo) streams */
);
/** Get or set options on a multistream decoder state */
OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request , ...) OPUS_ARG_NONNULL(1); OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request , ...) OPUS_ARG_NONNULL(1);
/** Deallocate a multistream decoder state object */ /** Frees an <code>OpusMSDecoder</code> allocated by
* opus_multistream_decoder_create().
* @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed
.
*/
OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
/**@}*/
/**@}*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* OPUS_MULTISTREAM_H */ #endif /* OPUS_MULTISTREAM_H */
 End of changes. 30 change blocks. 
117 lines changed or deleted 669 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/