Expand description
Safe, ergonomic wrappers around libopus for encoding/decoding Opus audio.
Re-exports§
pub use constants::MAX_FRAME_SAMPLES_48KHZ;pub use constants::MAX_PACKET_DURATION_MS;pub use constants::max_frame_samples_for;pub use decoder::Decoder;pub use encoder::Encoder;pub use error::Error;pub use error::Result;pub use multistream::MSDecoder;pub use multistream::MSEncoder;pub use multistream::Mapping;pub use packet::packet_bandwidth;pub use packet::packet_channels;pub use packet::packet_has_lbrr;pub use packet::packet_nb_frames;pub use packet::packet_nb_samples;pub use packet::packet_parse;pub use packet::packet_samples_per_frame;pub use packet::soft_clip;pub use projection::ProjectionDecoder;pub use projection::ProjectionEncoder;pub use repacketizer::Repacketizer;pub use types::Application;pub use types::Bandwidth;pub use types::Bitrate;pub use types::Channels;pub use types::Complexity;pub use types::ExpertFrameDuration;pub use types::FrameSize;pub use types::SampleRate;pub use types::Signal;
Modules§
- constants
- Crate-wide constants and small helpers
- decoder
- Opus decoder implementation with safe wrappers
- encoder
- Opus encoder implementation with safe wrappers
- error
- Error types for Opus codec operations
- multistream
- Safe wrappers for the Opus Multistream API (surround and channel-mapped streams)
- packet
- Safe helpers around opus packet inspection and parsing
- projection
- Safe wrappers for the libopus projection (ambisonics) API
- repacketizer
- Safe wrapper for
OpusRepacketizerutilities - types
- Common types and constants used by the Opus codec
Functions§
- opus_
decode ⚠ - Decode an Opus packet. @param [in] st OpusDecoder*: Decoder state @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss @param [in] len opus_int32: Number of bytes in payload* @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length is frame_sizechannelssizeof(opus_int16) @param [in] frame_size Number of samples per channel of available space in \a pcm. If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param [in] decode_fec int: 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 were lost. @returns Number of decoded samples or @ref opus_errorcodes
- opus_
decode_ ⚠float - Decode an Opus packet with floating point output. @param [in] st OpusDecoder*: Decoder state @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss @param [in] len opus_int32: Number of bytes in payload @param [out] pcm float*: Output signal (interleaved if 2 channels). length is frame_sizechannelssizeof(float) @param [in] frame_size Number of samples per channel of available space in \a pcm. If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param [in] decode_fec int: 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 were lost. @returns Number of decoded samples or @ref opus_errorcodes
- opus_
decoder_ ⚠create - Allocates and initializes a decoder state. @param [in] Fs opus_int32: Sample rate to decode at (Hz). This must be one of 8000, 12000, 16000, 24000, or 48000. @param [in] channels int: Number of channels (1 or 2) to decode @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes
- opus_
decoder_ ⚠ctl - Perform a CTL function on an Opus decoder.
- opus_
decoder_ ⚠destroy - Frees an
OpusDecoderallocated by opus_decoder_create(). @param[in] st OpusDecoder*: State to be freed. - opus_
decoder_ ⚠dred_ decode - Decode audio from an Opus DRED packet with floating point output. @param [in] st OpusDecoder*: Decoder state @param [in] dred OpusDRED*: DRED state @param [in] dred_offset opus_int32: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet). @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length is frame_sizechannelssizeof(opus_int16) @param [in] frame_size Number of samples per channel to decode in \a pcm. frame_size must be a multiple of 2.5 ms. @returns Number of decoded samples or @ref opus_errorcodes
- opus_
decoder_ ⚠dred_ decode_ float - Decode audio from an Opus DRED packet with floating point output. @param [in] st OpusDecoder*: Decoder state @param [in] dred OpusDRED*: DRED state @param [in] dred_offset opus_int32: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet). @param [out] pcm float*: Output signal (interleaved if 2 channels). length is frame_sizechannelssizeof(float) @param [in] frame_size Number of samples per channel to decode in \a pcm. frame_size must be a multiple of 2.5 ms. @returns Number of decoded samples or @ref opus_errorcodes
- opus_
decoder_ ⚠get_ nb_ samples - Gets the number of samples of an Opus packet. @param [in] dec OpusDecoder*: Decoder state @param [in] packet char*: Opus packet @param [in] len opus_int32: Length of packet @returns Number of samples @retval OPUS_BAD_ARG Insufficient data was passed to the function @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
decoder_ ⚠get_ size - Gets the size of an
OpusDecoderstructure. @param [in] channels int: Number of channels. This must be 1 or 2. @returns The size in bytes. - opus_
decoder_ ⚠init - Initializes a previously allocated decoder state. 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 To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. @param [in] st OpusDecoder*: Decoder state. @param [in] Fs opus_int32: Sampling rate to decode to (Hz). This must be one of 8000, 12000, 16000, 24000, or 48000. @param [in] channels int: Number of channels (1 or 2) to decode @retval #OPUS_OK Success or @ref opus_errorcodes
- opus_
dred_ ⚠alloc - Allocates and initializes a DRED state. @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes
- opus_
dred_ ⚠decoder_ create - Allocates and initializes an OpusDREDDecoder state. @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes
- opus_
dred_ ⚠decoder_ ctl - Perform a CTL function on an Opus DRED decoder.
- opus_
dred_ ⚠decoder_ destroy - Frees an
OpusDREDDecoderallocated by opus_dred_decoder_create(). @param[in] dec OpusDREDDecoder*: State to be freed. - opus_
dred_ ⚠decoder_ get_ size - Gets the size of an
OpusDREDDecoderstructure. @returns The size in bytes. - opus_
dred_ ⚠decoder_ init - Initializes an
OpusDREDDecoderstate. @param[in] dec OpusDREDDecoder*: State to be initialized. - opus_
dred_ ⚠free - Frees an
OpusDREDallocated by opus_dred_create(). @param[in] dec OpusDRED*: State to be freed. - opus_
dred_ ⚠get_ size - Gets the size of an
OpusDREDstructure. @returns The size in bytes. - opus_
dred_ ⚠parse - Decode an Opus DRED packet. @param [in] dred_dec OpusDRED*: DRED Decoder state @param [in] dred OpusDRED*: DRED state @param [in] data char*: Input payload @param [in] len opus_int32: Number of bytes in payload @param [in] max_dred_samples opus_int32: Maximum number of DRED samples that may be needed (if available in the packet). @param [in] sampling_rate opus_int32: Sampling rate used for max_dred_samples argument. Needs not match the actual sampling rate of the decoder. @param [out] dred_end opus_int32*: Number of non-encoded (silence) samples between the DRED timestamp and the last DRED sample. @param [in] defer_processing int: Flag (0 or 1). If set to one, the CPU-intensive part of the DRED decoding is deferred until opus_dred_process() is called. @returns Offset (positive) of the first decoded DRED samples, zero if no DRED is present, or @ref opus_errorcodes
- opus_
dred_ ⚠process - Finish decoding an Opus DRED packet. The function only needs to be called if opus_dred_parse() was called with defer_processing=1. The source and destination will often be the same DRED state. @param [in] dred_dec OpusDRED*: DRED Decoder state @param [in] src OpusDRED*: Source DRED state to start the processing from. @param [out] dst OpusDRED*: Destination DRED state to store the updated state after processing. @returns @ref opus_errorcodes
- opus_
encode ⚠ - Encodes an Opus frame. @param [in] st OpusEncoder*: Encoder state @param [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_sizechannelssizeof(opus_int16) @param [in] frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char*: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
encode_ ⚠float - Encodes an Opus frame from floating point input. @param [in] st OpusEncoder*: Encoder state @param [in] pcm float*: 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 be clipped by decoders using the integer API and should only be used if it is known that the far end supports extended dynamic range. length is frame_sizechannelssizeof(float) @param [in] frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char*: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
encoder_ ⚠create - Allocates and initializes an encoder state. There are three coding modes:
- opus_
encoder_ ⚠ctl - Perform a CTL function on an Opus encoder.
- opus_
encoder_ ⚠destroy - Frees an
OpusEncoderallocated by opus_encoder_create(). @param[in] st OpusEncoder*: State to be freed. - opus_
encoder_ ⚠get_ size - Gets the size of an
OpusEncoderstructure. @param[in] channels int: Number of channels. This must be 1 or 2. @returns The size in bytes. - opus_
encoder_ ⚠init - Initializes a previously allocated encoder state 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. @see opus_encoder_create(),opus_encoder_get_size() To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. @param [in] st OpusEncoder*: Encoder state @param [in] Fs opus_int32: Sampling rate of input signal (Hz) This must be one of 8000, 12000, 16000, 24000, or 48000. @param [in] channels int: Number of channels (1 or 2) in input signal @param [in] application int: Coding mode (one of OPUS_APPLICATION_VOIP, OPUS_APPLICATION_AUDIO, or OPUS_APPLICATION_RESTRICTED_LOWDELAY) @retval #OPUS_OK Success or @ref opus_errorcodes
- opus_
get_ ⚠version_ string - Gets the libopus version string.
- opus_
multistream_ ⚠decode - Decode a multistream Opus packet.
@param st OpusMSDecoder*: Multistream decoder state.
@param[in] data const unsigned char*: Input payload.
Use a
NULLpointer to indicate packet loss. @param len opus_int32: Number of bytes in payload. @param[out] pcm opus_int16*: Output signal, with interleaved samples. This must contain room forframe_size*channelssamples. @param frame_size int: 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 of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param decode_fec int: 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 were lost. @returns Number of samples decoded on success or a negative error code (see @ref opus_errorcodes) on failure. - opus_
multistream_ ⚠decode_ float - Decode a multistream Opus packet with floating point output.
@param st OpusMSDecoder*: Multistream decoder state.
@param[in] data const unsigned char*: Input payload.
Use a
NULLpointer to indicate packet loss. @param len opus_int32: Number of bytes in payload. @param[out] pcm opus_int16*: Output signal, with interleaved samples. This must contain room forframe_size*channelssamples. @param frame_size int: 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 of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param decode_fec int: 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 were lost. @returns Number of samples decoded on success or a negative error code (see @ref opus_errorcodes) on failure. - opus_
multistream_ ⚠decoder_ create - Allocates and initializes a multistream decoder state.
Call opus_multistream_decoder_destroy() to release
this object when finished.
@param Fs opus_int32: Sampling rate to decode at (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels to output.
This must be at most 255.
It may be different from the number of coded
channels (
streams + coupled_streams). @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number of streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) must be no more than 255. @param[in] mappingconst unsigned char[channels]: Mapping from coded channels to output channels, as described in @ref opus_multistream. @param[out] error int *: Returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) on failure. - opus_
multistream_ ⚠decoder_ ctl - Perform a CTL function on a multistream Opus decoder.
- opus_
multistream_ ⚠decoder_ destroy - Frees an
OpusMSDecoderallocated by opus_multistream_decoder_create(). @param st OpusMSDecoder: Multistream decoder state to be freed. - opus_
multistream_ ⚠decoder_ get_ size - Gets the size of an
OpusMSDecoderstructure. @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) 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_
multistream_ ⚠decoder_ init - 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 OpusMSEncoder*: Multistream encoder state to initialize.
@param Fs opus_int32: Sampling rate to decode at (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels to output.
This must be at most 255.
It may be different from the number of coded
channels (
streams + coupled_streams). @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number of streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) must be no more than 255. @param[in] mappingconst unsigned char[channels]: 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_errorcodes) on failure. - opus_
multistream_ ⚠encode - Encodes a multistream Opus frame.
@param st OpusMSEncoder*: Multistream encoder state.
@param[in] pcm const opus_int16*: The input signal as interleaved
samples.
This must contain
frame_sizechannelssamples. @param frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
multistream_ ⚠encode_ float - Encodes a multistream Opus frame from floating point input.
@param st OpusMSEncoder*: Multistream encoder state.
@param[in] pcm const float*: 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 and
should only be used if it is known
that the far end supports extended
dynamic range.
This must contain
frame_sizechannelssamples. @param frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
multistream_ ⚠encoder_ create - Allocates and initializes a multistream encoder state.
Call opus_multistream_encoder_destroy() to release
this object when finished.
@param Fs opus_int32: Sampling rate of the input signal (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels in the input signal.
This must be at most 255.
It may be greater than the number of
coded channels (
streams + coupled_streams). @param streams int: The total number of streams to encode from the input. This must be no more than the number of channels. @param coupled_streams int: Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than the number of input channels. @param[in] mappingconst unsigned char[channels]: 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 int: The target encoder application. This must be one of the following: - opus_
multistream_ ⚠encoder_ ctl - Perform a CTL function on a multistream Opus encoder.
- opus_
multistream_ ⚠encoder_ destroy - Frees an
OpusMSEncoderallocated by opus_multistream_encoder_create(). @param st OpusMSEncoder*: Multistream encoder state to be freed. - opus_
multistream_ ⚠encoder_ get_ size - Gets the size of an OpusMSEncoder structure.
@param streams int: The total number of streams to encode from the
input.
This must be no more than 255.
@param coupled_streams int: Number of coupled (2 channel) streams
to encode.
This must be no larger than the total
number of streams.
Additionally, The total number of
encoded channels (
streams + coupled_streams) 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_
multistream_ ⚠encoder_ init - 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 OpusMSEncoder*: Multistream encoder state to initialize.
@param Fs opus_int32: Sampling rate of the input signal (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels in the input signal.
This must be at most 255.
It may be greater than the number of
coded channels (
streams + coupled_streams). @param streams int: The total number of streams to encode from the input. This must be no more than the number of channels. @param coupled_streams int: Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than the number of input channels. @param[in] mappingconst unsigned char[channels]: 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 int: The target encoder application. This must be one of the following: - opus_
multistream_ ⚠packet_ pad - Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). @param[in,out] data const unsigned char*: The buffer containing the packet to pad. @param len opus_int32: The size of the packet. This must be at least 1. @param new_len opus_int32: The desired size of the packet after padding. This must be at least 1. @param nb_streams opus_int32: The number of streams (not channels) in the packet. This must be at least as large as len. @returns an error code @retval #OPUS_OK \a on success. @retval #OPUS_BAD_ARG \a len was less than 1. @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet.
- opus_
multistream_ ⚠packet_ unpad - Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to minimize space usage. @param[in,out] data const unsigned char*: The buffer containing the packet to strip. @param len opus_int32: The size of the packet. This must be at least 1. @param nb_streams opus_int32: The number of streams (not channels) in the packet. This must be at least 1. @returns The new size of the output packet on success, or an error code on failure. @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet.
- opus_
multistream_ ⚠surround_ encoder_ create - opus_
multistream_ ⚠surround_ encoder_ get_ size - opus_
multistream_ ⚠surround_ encoder_ init - opus_
packet_ ⚠get_ bandwidth - Gets the bandwidth of an Opus packet. @param [in] data char*: Opus packet @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
packet_ ⚠get_ nb_ channels - Gets the number of channels from an Opus packet. @param [in] data char*: Opus packet @returns Number of channels @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
packet_ ⚠get_ nb_ frames - Gets the number of frames in an Opus packet. @param [in] packet char*: Opus packet @param [in] len opus_int32: Length of packet @returns Number of frames @retval OPUS_BAD_ARG Insufficient data was passed to the function @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
packet_ ⚠get_ nb_ samples - Gets the number of samples of an Opus packet. @param [in] packet char*: Opus packet @param [in] len opus_int32: Length of packet @param [in] Fs opus_int32: Sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned. @returns Number of samples @retval OPUS_BAD_ARG Insufficient data was passed to the function @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
packet_ ⚠get_ samples_ per_ frame - Gets the number of samples per frame from an Opus packet. @param [in] data char*: Opus packet. This must contain at least one byte of data. @param [in] Fs opus_int32: Sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned. @returns Number of samples per frame.
- opus_
packet_ ⚠has_ lbrr - Checks whether an Opus packet has LBRR. @param [in] packet char*: Opus packet @param [in] len opus_int32: Length of packet @returns 1 is LBRR is present, 0 otherwise @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
- opus_
packet_ ⚠pad - Pads a given Opus packet to a larger size (possibly changing the TOC sequence). @param[in,out] data const unsigned char*: The buffer containing the packet to pad. @param len opus_int32: The size of the packet. This must be at least 1. @param new_len opus_int32: The desired size of the packet after padding. This must be at least as large as len. @returns an error code @retval #OPUS_OK \a on success. @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet.
- opus_
packet_ ⚠parse - Parse an opus packet into one or more frames. Opus_decode will perform this operation internally so most applications do not need to use this function. This function does not copy the frames, the returned pointers are pointers into the input packet. @param [in] data char*: Opus packet to be parsed @param [in] len opus_int32: size of data @param [out] out_toc char*: TOC pointer @param [out] frames char*[48] encapsulated frames @param [out] size opus_int16[48] sizes of the encapsulated frames @param [out] payload_offset int*: returns the position of the payload within the packet (in bytes) @returns number of frames
- opus_
packet_ ⚠unpad - Remove all padding from a given Opus packet and rewrite the TOC sequence to minimize space usage. @param[in,out] data const unsigned char*: The buffer containing the packet to strip. @param len opus_int32: The size of the packet. This must be at least 1. @returns The new size of the output packet on success, or an error code on failure. @retval #OPUS_BAD_ARG \a len was less than 1. @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet.
- opus_
pcm_ ⚠soft_ clip - Applies soft-clipping to bring a float signal within the [-1,1] range. If the signal is already in that range, nothing is done. If there are values outside of [-1,1], then the signal is clipped as smoothly as possible to both fit in the range and avoid creating excessive distortion in the process. @param [in,out] pcm float*: Input PCM and modified PCM @param [in] frame_size int Number of samples per channel to process @param [in] channels int: Number of channels @param [in,out] softclip_mem float*: State memory for the soft clipping process (one float per channel, initialized to zero)
- opus_
projection_ ⚠ambisonics_ encoder_ create - Allocates and initializes a projection encoder state.
Call opus_projection_encoder_destroy() to release
this object when finished.
@param Fs opus_int32: Sampling rate of the input signal (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels in the input signal.
This must be at most 255.
It may be greater than the number of
coded channels (
streams + coupled_streams). @param mapping_family int: The mapping family to use for selecting the appropriate projection. @param[out] streams int *: The total number of streams that will be encoded from the input. @param[out] coupled_streams int *: Number of coupled (2 channel) streams that will be encoded from the input. @param application int: The target encoder application. This must be one of the following: - opus_
projection_ ⚠ambisonics_ encoder_ get_ size - Gets the size of an OpusProjectionEncoder structure. @param channels int: The total number of input channels to encode. This must be no more than 255. @param mapping_family int: The mapping family to use for selecting the appropriate projection. @returns The size in bytes on success, or a negative error code (see @ref opus_errorcodes) on error.
- opus_
projection_ ⚠ambisonics_ encoder_ init - Initialize a previously allocated projection encoder state.
The memory pointed to by \a st must be at least the size returned by
opus_projection_ambisonics_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_projection_ambisonics_encoder_create
@see opus_projection_ambisonics_encoder_get_size
@param st OpusProjectionEncoder*: Projection encoder state to initialize.
@param Fs opus_int32: Sampling rate of the input signal (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels in the input signal.
This must be at most 255.
It may be greater than the number of
coded channels (
streams + coupled_streams). @param streams int: The total number of streams to encode from the input. This must be no more than the number of channels. @param coupled_streams int: Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than the number of input channels. @param application int: The target encoder application. This must be one of the following: - opus_
projection_ ⚠decode - Decode a projection Opus packet.
@param st OpusProjectionDecoder*: Projection decoder state.
@param[in] data const unsigned char*: Input payload.
Use a
NULLpointer to indicate packet loss. @param len opus_int32: Number of bytes in payload. @param[out] pcm opus_int16*: Output signal, with interleaved samples. This must contain room forframe_size*channelssamples. @param frame_size int: 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 of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param decode_fec int: 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 were lost. @returns Number of samples decoded on success or a negative error code (see @ref opus_errorcodes) on failure. - opus_
projection_ ⚠decode_ float - Decode a projection Opus packet with floating point output.
@param st OpusProjectionDecoder*: Projection decoder state.
@param[in] data const unsigned char*: Input payload.
Use a
NULLpointer to indicate packet loss. @param len opus_int32: Number of bytes in payload. @param[out] pcm opus_int16*: Output signal, with interleaved samples. This must contain room forframe_size*channelssamples. @param frame_size int: 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 of 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 state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms. @param decode_fec int: 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 were lost. @returns Number of samples decoded on success or a negative error code (see @ref opus_errorcodes) on failure. - opus_
projection_ ⚠decoder_ create - Allocates and initializes a projection decoder state.
Call opus_projection_decoder_destroy() to release
this object when finished.
@param Fs opus_int32: Sampling rate to decode at (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels to output.
This must be at most 255.
It may be different from the number of coded
channels (
streams + coupled_streams). @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number of streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) must be no more than 255. @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix that mapping from coded channels to output channels, as described in @ref opus_projection and @ref opus_projection_ctls. @param demixing_matrix_size opus_int32: The size in bytes of the demixing matrix, as described in @ref opus_projection_ctls. @param[out] error int *: Returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) on failure. - opus_
projection_ ⚠decoder_ ctl - Perform a CTL function on a projection Opus decoder.
- opus_
projection_ ⚠decoder_ destroy - Frees an
OpusProjectionDecoderallocated by opus_projection_decoder_create(). @param st OpusProjectionDecoder: Projection decoder state to be freed. - opus_
projection_ ⚠decoder_ get_ size - Gets the size of an
OpusProjectionDecoderstructure. @param channels int: The total number of output channels. This must be no more than 255. @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) 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_
projection_ ⚠decoder_ init - Intialize a previously allocated projection decoder state object.
The memory pointed to by \a st must be at least the size returned by
opus_projection_decoder_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_projection_decoder_create
@see opus_projection_deocder_get_size
@param st OpusProjectionDecoder*: Projection encoder state to initialize.
@param Fs opus_int32: Sampling rate to decode at (in Hz).
This must be one of 8000, 12000, 16000,
24000, or 48000.
@param channels int: Number of channels to output.
This must be at most 255.
It may be different from the number of coded
channels (
streams + coupled_streams). @param streams int: The total number of streams coded in the input. This must be no more than 255. @param coupled_streams int: Number of streams to decode as coupled (2 channel) streams. This must be no larger than the total number of streams. Additionally, The total number of coded channels (streams + coupled_streams) must be no more than 255. @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix that mapping from coded channels to output channels, as described in @ref opus_projection and @ref opus_projection_ctls. @param demixing_matrix_size opus_int32: The size in bytes of the demixing matrix, as described in @ref opus_projection_ctls. @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) on failure. - opus_
projection_ ⚠encode - Encodes a projection Opus frame.
@param st OpusProjectionEncoder*: Projection encoder state.
@param[in] pcm const opus_int16*: The input signal as interleaved
samples.
This must contain
frame_sizechannelssamples. @param frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
projection_ ⚠encode_ float - Encodes a projection Opus frame from floating point input.
@param st OpusProjectionEncoder*: Projection encoder state.
@param[in] pcm const float*: 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 and
should only be used if it is known
that the far end supports extended
dynamic range.
This must contain
frame_sizechannelssamples. @param frame_size int: Number of samples per channel in the input signal. This must be an Opus frame size for the encoder’s sampling rate. For example, at 48 kHz the permitted values are 120, 240, 480, 960, 1920, 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 unsigned char: Output payload. This must contain storage for at least \a max_data_bytes. @param [in] max_data_bytes opus_int32: Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but 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_
projection_ ⚠encoder_ ctl - Perform a CTL function on a projection Opus encoder.
- opus_
projection_ ⚠encoder_ destroy - Frees an
OpusProjectionEncoderallocated by opus_projection_ambisonics_encoder_create(). @param st OpusProjectionEncoder*: Projection encoder state to be freed. - opus_
repacketizer_ ⚠cat - Add a packet to the current repacketizer state. This packet must match the configuration of any packets already submitted for repacketization since the last call to opus_repacketizer_init(). This means that it must have the same coding mode, audio bandwidth, frame 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 exceed 120 ms, the maximum duration of a single packet, after adding this packet.
- opus_
repacketizer_ ⚠create - Allocates memory and initializes the new repacketizer with opus_repacketizer_init().
- opus_
repacketizer_ ⚠destroy - Frees an
OpusRepacketizerallocated by opus_repacketizer_create(). @param[in] rp OpusRepacketizer*: State to be freed. - opus_
repacketizer_ ⚠get_ nb_ frames - Return the total number of frames contained in packet data submitted to the repacketizer state so far via opus_repacketizer_cat() since the last 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 OpusRepacketizer*: The repacketizer state containing the frames. @returns The total number of frames contained in the packet data submitted to the repacketizer state.
- opus_
repacketizer_ ⚠get_ size - Gets the size of an
OpusRepacketizerstructure. @returns The size in bytes. - opus_
repacketizer_ ⚠init - (Re)initializes a previously allocated repacketizer state. The state must be at least the size returned by opus_repacketizer_get_size(). 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 count). 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 OpusRepacketizer*: The repacketizer state to (re)initialize. @returns A pointer to the same repacketizer state that was passed in.
- opus_
repacketizer_ ⚠out - Construct a new packet from data previously submitted to the repacketizer
state via opus_repacketizer_cat().
This is a convenience routine that returns all the data submitted so far
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 OpusRepacketizer*: The repacketizer state from which to
construct the new packet.
@param[out] data const unsigned char*: The buffer in which to
store the output packet.
@param maxlen opus_int32: The maximum number of bytes to store in
the output buffer. In order to guarantee
success, this should be at least
1277opus_repacketizer_get_nb_frames(rp). However,1opus_repacketizer_get_nb_frames(rp)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 smaller. @returns The total size of the output packet on success, or an error code on failure. @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the complete output packet. - opus_
repacketizer_ ⚠out_ range - Construct a new packet from data previously submitted to the repacketizer
state via opus_repacketizer_cat().
@param rp OpusRepacketizer*: The repacketizer state from which to
construct the new packet.
@param begin int: The index of the first frame in the current
repacketizer state to include in the output.
@param end int: One past the index of the last frame in the
current repacketizer state to include in the
output.
@param[out] data const unsigned char*: The buffer in which to
store the output packet.
@param maxlen opus_int32: The maximum number of bytes to store in
the output buffer. In order to guarantee
success, this should be at least
1276for a single frame, or for multiple frames,1277*(end-begin). However,1*(end-begin)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 smaller. @returns The total size of the output packet on success, or an error code on failure. @retval #OPUS_BAD_ARG[begin,end)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 the complete output packet. - opus_
strerror ⚠ - Converts an opus error code into a human readable string.
- runtime_
version - Returns the runtime libopus version string from the linked C library.
- strerror
- Returns a human-readable string for a libopus error code (via runtime library).
- version
- Returns the bundled libopus version string of this crate.