Chris@70: /* Copyright (c) 2011 Xiph.Org Foundation
Chris@70: Written by Jean-Marc Valin */
Chris@70: /*
Chris@70: Redistribution and use in source and binary forms, with or without
Chris@70: modification, are permitted provided that the following conditions
Chris@70: are met:
Chris@70:
Chris@70: - Redistributions of source code must retain the above copyright
Chris@70: notice, this list of conditions and the following disclaimer.
Chris@70:
Chris@70: - Redistributions in binary form must reproduce the above copyright
Chris@70: notice, this list of conditions and the following disclaimer in the
Chris@70: documentation and/or other materials provided with the distribution.
Chris@70:
Chris@70: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@70: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@70: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@70: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@70: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@70: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@70: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@70: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@70: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@70: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@70: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@70: */
Chris@70:
Chris@70: /**
Chris@70: * @file opus_multistream.h
Chris@70: * @brief Opus reference implementation multistream API
Chris@70: */
Chris@70:
Chris@70: #ifndef OPUS_MULTISTREAM_H
Chris@70: #define OPUS_MULTISTREAM_H
Chris@70:
Chris@70: #include "opus.h"
Chris@70:
Chris@70: #ifdef __cplusplus
Chris@70: extern "C" {
Chris@70: #endif
Chris@70:
Chris@70: /** @cond OPUS_INTERNAL_DOC */
Chris@70:
Chris@70: /** Macros to trigger compilation errors when the wrong types are provided to a
Chris@70: * CTL. */
Chris@70: /**@{*/
Chris@70: #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
Chris@70: #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
Chris@70: /**@}*/
Chris@70:
Chris@70: /** These are the actual encoder and decoder CTL ID numbers.
Chris@70: * They should not be used directly by applications.
Chris@70: * In general, SETs should be even and GETs should be odd.*/
Chris@70: /**@{*/
Chris@70: #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
Chris@70: #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
Chris@70: /**@}*/
Chris@70:
Chris@70: /** @endcond */
Chris@70:
Chris@70: /** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs
Chris@70: *
Chris@70: * These are convenience macros that are specific to the
Chris@70: * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl()
Chris@70: * interface.
Chris@70: * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and
Chris@70: * @ref opus_decoderctls may be applied to a multistream encoder or decoder as
Chris@70: * well.
Chris@70: * In addition, you may retrieve the encoder or decoder state for an specific
Chris@70: * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or
Chris@70: * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
Chris@70: */
Chris@70: /**@{*/
Chris@70:
Chris@70: /** Gets the encoder state for an individual stream of a multistream encoder.
Chris@70: * @param[in] x opus_int32: The index of the stream whose encoder you
Chris@70: * wish to retrieve.
Chris@70: * This must be non-negative and less than
Chris@70: * the streams
parameter used
Chris@70: * to initialize the encoder.
Chris@70: * @param[out] y OpusEncoder**: Returns a pointer to the given
Chris@70: * encoder state.
Chris@70: * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
Chris@70: * @hideinitializer
Chris@70: */
Chris@70: #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
Chris@70:
Chris@70: /** Gets the decoder state for an individual stream of a multistream decoder.
Chris@70: * @param[in] x opus_int32: The index of the stream whose decoder you
Chris@70: * wish to retrieve.
Chris@70: * This must be non-negative and less than
Chris@70: * the streams
parameter used
Chris@70: * to initialize the decoder.
Chris@70: * @param[out] y OpusDecoder**: Returns a pointer to the given
Chris@70: * decoder state.
Chris@70: * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
Chris@70: * @hideinitializer
Chris@70: */
Chris@70: #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
Chris@70:
Chris@70: /**@}*/
Chris@70:
Chris@70: /** @defgroup opus_multistream Opus Multistream API
Chris@70: * @{
Chris@70: *
Chris@70: * The multistream API allows individual Opus streams to be combined into a
Chris@70: * single packet, enabling support for up to 255 channels. Unlike an
Chris@70: * elementary Opus stream, the encoder and decoder must negotiate the channel
Chris@70: * configuration before the decoder can successfully interpret the data in the
Chris@70: * packets produced by the encoder. Some basic information, such as packet
Chris@70: * duration, can be computed without any special negotiation.
Chris@70: *
Chris@70: * The format for multistream Opus packets is defined in
Chris@70: * RFC 7845
Chris@70: * and is based on the self-delimited Opus framing described in Appendix B of
Chris@70: * RFC 6716.
Chris@70: * Normal Opus packets are just a degenerate case of multistream Opus packets,
Chris@70: * and can be encoded or decoded with the multistream API by setting
Chris@70: * streams
to 1
when initializing the encoder or
Chris@70: * decoder.
Chris@70: *
Chris@70: * Multistream Opus streams can contain up to 255 elementary Opus streams.
Chris@70: * These may be either "uncoupled" or "coupled", indicating that the decoder
Chris@70: * is configured to decode them to either 1 or 2 channels, respectively.
Chris@70: * The streams are ordered so that all coupled streams appear at the
Chris@70: * beginning.
Chris@70: *
Chris@70: * A mapping
table defines which decoded channel i
Chris@70: * should be used for each input/output (I/O) channel j
. This table is
Chris@70: * typically provided as an unsigned char array.
Chris@70: * Let i = mapping[j]
be the index for I/O channel j
.
Chris@70: * If i < 2*coupled_streams
, then I/O channel j
is
Chris@70: * encoded as the left channel of stream (i/2)
if i
Chris@70: * is even, or as the right channel of stream (i/2)
if
Chris@70: * i
is odd. Otherwise, I/O channel j
is encoded as
Chris@70: * mono in stream (i - coupled_streams)
, unless it has the special
Chris@70: * value 255, in which case it is omitted from the encoding entirely (the
Chris@70: * decoder will reproduce it as silence). Each value i
must either
Chris@70: * be the special value 255 or be less than streams + coupled_streams
.
Chris@70: *
Chris@70: * The output channels specified by the encoder
Chris@70: * should use the
Chris@70: * Vorbis
Chris@70: * channel ordering. A decoder may wish to apply an additional permutation
Chris@70: * to the mapping the encoder used to achieve a different output channel
Chris@70: * order (e.g. for outputing in WAV order).
Chris@70: *
Chris@70: * Each multistream packet contains an Opus packet for each stream, and all of
Chris@70: * the Opus packets in a single multistream packet must have the same
Chris@70: * duration. Therefore the duration of a multistream packet can be extracted
Chris@70: * from the TOC sequence of the first stream, which is located at the
Chris@70: * beginning of the packet, just like an elementary Opus stream:
Chris@70: *
Chris@70: * @code
Chris@70: * int nb_samples;
Chris@70: * int nb_frames;
Chris@70: * nb_frames = opus_packet_get_nb_frames(data, len);
Chris@70: * if (nb_frames < 1)
Chris@70: * return nb_frames;
Chris@70: * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;
Chris@70: * @endcode
Chris@70: *
Chris@70: * The general encoding and decoding process proceeds exactly the same as in
Chris@70: * the normal @ref opus_encoder and @ref opus_decoder APIs.
Chris@70: * See their documentation for an overview of how to use the corresponding
Chris@70: * multistream functions.
Chris@70: */
Chris@70:
Chris@70: /** Opus multistream encoder state.
Chris@70: * This contains the complete state of a multistream Opus encoder.
Chris@70: * It is position independent and can be freely copied.
Chris@70: * @see opus_multistream_encoder_create
Chris@70: * @see opus_multistream_encoder_init
Chris@70: */
Chris@70: typedef struct OpusMSEncoder OpusMSEncoder;
Chris@70:
Chris@70: /** Opus multistream decoder state.
Chris@70: * This contains the complete state of a multistream Opus decoder.
Chris@70: * It is position independent and can be freely copied.
Chris@70: * @see opus_multistream_decoder_create
Chris@70: * @see opus_multistream_decoder_init
Chris@70: */
Chris@70: typedef struct OpusMSDecoder OpusMSDecoder;
Chris@70:
Chris@70: /**\name Multistream encoder functions */
Chris@70: /**@{*/
Chris@70:
Chris@70: /** Gets the size of an OpusMSEncoder structure.
Chris@70: * @param streams int: The total number of streams to encode from the
Chris@70: * input.
Chris@70: * This must be no more than 255.
Chris@70: * @param coupled_streams int: Number of coupled (2 channel) streams
Chris@70: * to encode.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * encoded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than 255.
Chris@70: * @returns The size in bytes on success, or a negative error code
Chris@70: * (see @ref opus_errorcodes) on error.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
Chris@70: int streams,
Chris@70: int coupled_streams
Chris@70: );
Chris@70:
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size(
Chris@70: int channels,
Chris@70: int mapping_family
Chris@70: );
Chris@70:
Chris@70:
Chris@70: /** Allocates and initializes a multistream encoder state.
Chris@70: * Call opus_multistream_encoder_destroy() to release
Chris@70: * this object when finished.
Chris@70: * @param Fs opus_int32: Sampling rate of the input signal (in Hz).
Chris@70: * This must be one of 8000, 12000, 16000,
Chris@70: * 24000, or 48000.
Chris@70: * @param channels int: Number of channels in the input signal.
Chris@70: * This must be at most 255.
Chris@70: * It may be greater than the number of
Chris@70: * coded channels (streams +
Chris@70: * coupled_streams
).
Chris@70: * @param streams int: The total number of streams to encode from the
Chris@70: * input.
Chris@70: * This must be no more than the number of channels.
Chris@70: * @param coupled_streams int: Number of coupled (2 channel) streams
Chris@70: * to encode.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * encoded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than the number of input channels.
Chris@70: * @param[in] mapping const unsigned char[channels]
: Mapping from
Chris@70: * encoded channels to input channels, as described in
Chris@70: * @ref opus_multistream. As an extra constraint, the
Chris@70: * multistream encoder does not allow encoding coupled
Chris@70: * streams for which one channel is unused since this
Chris@70: * is never a good idea.
Chris@70: * @param application int: The target encoder application.
Chris@70: * This must be one of the following:
Chris@70: *
streams +
Chris@70: * coupled_streams
).
Chris@70: * @param streams int: The total number of streams to encode from the
Chris@70: * input.
Chris@70: * This must be no more than the number of channels.
Chris@70: * @param coupled_streams int: Number of coupled (2 channel) streams
Chris@70: * to encode.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * encoded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than the number of input channels.
Chris@70: * @param[in] mapping const unsigned char[channels]
: Mapping from
Chris@70: * encoded channels to input channels, as described in
Chris@70: * @ref opus_multistream. As an extra constraint, the
Chris@70: * multistream encoder does not allow encoding coupled
Chris@70: * streams for which one channel is unused since this
Chris@70: * is never a good idea.
Chris@70: * @param application int: The target encoder application.
Chris@70: * This must be one of the following:
Chris@70: * frame_size*channels
Chris@70: * samples.
Chris@70: * @param frame_size int: Number of samples per channel in the input
Chris@70: * signal.
Chris@70: * This must be an Opus frame size for the
Chris@70: * encoder's sampling rate.
Chris@70: * For example, at 48 kHz the permitted values
Chris@70: * are 120, 240, 480, 960, 1920, and 2880.
Chris@70: * Passing in a duration of less than 10 ms
Chris@70: * (480 samples at 48 kHz) will prevent the
Chris@70: * encoder from using the LPC or hybrid modes.
Chris@70: * @param[out] data unsigned char*: Output payload.
Chris@70: * This must contain storage for at
Chris@70: * least \a max_data_bytes.
Chris@70: * @param [in] max_data_bytes opus_int32: Size of the allocated
Chris@70: * memory for the output
Chris@70: * payload. This may be
Chris@70: * used to impose an upper limit on
Chris@70: * the instant bitrate, but should
Chris@70: * not be used as the only bitrate
Chris@70: * control. Use #OPUS_SET_BITRATE to
Chris@70: * control the bitrate.
Chris@70: * @returns The length of the encoded packet (in bytes) on success or a
Chris@70: * negative error code (see @ref opus_errorcodes) on failure.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
Chris@70: OpusMSEncoder *st,
Chris@70: const opus_int16 *pcm,
Chris@70: int frame_size,
Chris@70: unsigned char *data,
Chris@70: opus_int32 max_data_bytes
Chris@70: ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Chris@70:
Chris@70: /** Encodes a multistream Opus frame from floating point input.
Chris@70: * @param st OpusMSEncoder*: Multistream encoder state.
Chris@70: * @param[in] pcm const float*: The input signal as interleaved
Chris@70: * samples with a normal range of
Chris@70: * +/-1.0.
Chris@70: * Samples with a range beyond +/-1.0
Chris@70: * are supported but will be clipped by
Chris@70: * decoders using the integer API and
Chris@70: * should only be used if it is known
Chris@70: * that the far end supports extended
Chris@70: * dynamic range.
Chris@70: * This must contain
Chris@70: * frame_size*channels
Chris@70: * samples.
Chris@70: * @param frame_size int: Number of samples per channel in the input
Chris@70: * signal.
Chris@70: * This must be an Opus frame size for the
Chris@70: * encoder's sampling rate.
Chris@70: * For example, at 48 kHz the permitted values
Chris@70: * are 120, 240, 480, 960, 1920, and 2880.
Chris@70: * Passing in a duration of less than 10 ms
Chris@70: * (480 samples at 48 kHz) will prevent the
Chris@70: * encoder from using the LPC or hybrid modes.
Chris@70: * @param[out] data unsigned char*: Output payload.
Chris@70: * This must contain storage for at
Chris@70: * least \a max_data_bytes.
Chris@70: * @param [in] max_data_bytes opus_int32: Size of the allocated
Chris@70: * memory for the output
Chris@70: * payload. This may be
Chris@70: * used to impose an upper limit on
Chris@70: * the instant bitrate, but should
Chris@70: * not be used as the only bitrate
Chris@70: * control. Use #OPUS_SET_BITRATE to
Chris@70: * control the bitrate.
Chris@70: * @returns The length of the encoded packet (in bytes) on success or a
Chris@70: * negative error code (see @ref opus_errorcodes) on failure.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
Chris@70: OpusMSEncoder *st,
Chris@70: const float *pcm,
Chris@70: int frame_size,
Chris@70: unsigned char *data,
Chris@70: opus_int32 max_data_bytes
Chris@70: ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Chris@70:
Chris@70: /** Frees an OpusMSEncoder
allocated by
Chris@70: * opus_multistream_encoder_create().
Chris@70: * @param st OpusMSEncoder*: Multistream encoder state to be freed.
Chris@70: */
Chris@70: OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
Chris@70:
Chris@70: /** Perform a CTL function on a multistream Opus encoder.
Chris@70: *
Chris@70: * Generally the request and subsequent arguments are generated by a
Chris@70: * convenience macro.
Chris@70: * @param st OpusMSEncoder*: Multistream encoder state.
Chris@70: * @param request This and all remaining parameters should be replaced by one
Chris@70: * of the convenience macros in @ref opus_genericctls,
Chris@70: * @ref opus_encoderctls, or @ref opus_multistream_ctls.
Chris@70: * @see opus_genericctls
Chris@70: * @see opus_encoderctls
Chris@70: * @see opus_multistream_ctls
Chris@70: */
Chris@70: OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Chris@70:
Chris@70: /**@}*/
Chris@70:
Chris@70: /**\name Multistream decoder functions */
Chris@70: /**@{*/
Chris@70:
Chris@70: /** Gets the size of an OpusMSDecoder
structure.
Chris@70: * @param streams int: The total number of streams coded in the
Chris@70: * input.
Chris@70: * This must be no more than 255.
Chris@70: * @param coupled_streams int: Number streams to decode as coupled
Chris@70: * (2 channel) streams.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * coded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than 255.
Chris@70: * @returns The size in bytes on success, or a negative error code
Chris@70: * (see @ref opus_errorcodes) on error.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
Chris@70: int streams,
Chris@70: int coupled_streams
Chris@70: );
Chris@70:
Chris@70: /** Allocates and initializes a multistream decoder state.
Chris@70: * Call opus_multistream_decoder_destroy() to release
Chris@70: * this object when finished.
Chris@70: * @param Fs opus_int32: Sampling rate to decode at (in Hz).
Chris@70: * This must be one of 8000, 12000, 16000,
Chris@70: * 24000, or 48000.
Chris@70: * @param channels int: Number of channels to output.
Chris@70: * This must be at most 255.
Chris@70: * It may be different from the number of coded
Chris@70: * channels (streams +
Chris@70: * coupled_streams
).
Chris@70: * @param streams int: The total number of streams coded in the
Chris@70: * input.
Chris@70: * This must be no more than 255.
Chris@70: * @param coupled_streams int: Number of streams to decode as coupled
Chris@70: * (2 channel) streams.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * coded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than 255.
Chris@70: * @param[in] mapping const unsigned char[channels]
: Mapping from
Chris@70: * coded channels to output channels, as described in
Chris@70: * @ref opus_multistream.
Chris@70: * @param[out] error int *: Returns #OPUS_OK on success, or an error
Chris@70: * code (see @ref opus_errorcodes) on
Chris@70: * failure.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
Chris@70: opus_int32 Fs,
Chris@70: int channels,
Chris@70: int streams,
Chris@70: int coupled_streams,
Chris@70: const unsigned char *mapping,
Chris@70: int *error
Chris@70: ) OPUS_ARG_NONNULL(5);
Chris@70:
Chris@70: /** Intialize a previously allocated decoder state object.
Chris@70: * The memory pointed to by \a st must be at least the size returned by
Chris@70: * opus_multistream_encoder_get_size().
Chris@70: * This is intended for applications which use their own allocator instead of
Chris@70: * malloc.
Chris@70: * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
Chris@70: * @see opus_multistream_decoder_create
Chris@70: * @see opus_multistream_deocder_get_size
Chris@70: * @param st OpusMSEncoder*: Multistream encoder state to initialize.
Chris@70: * @param Fs opus_int32: Sampling rate to decode at (in Hz).
Chris@70: * This must be one of 8000, 12000, 16000,
Chris@70: * 24000, or 48000.
Chris@70: * @param channels int: Number of channels to output.
Chris@70: * This must be at most 255.
Chris@70: * It may be different from the number of coded
Chris@70: * channels (streams +
Chris@70: * coupled_streams
).
Chris@70: * @param streams int: The total number of streams coded in the
Chris@70: * input.
Chris@70: * This must be no more than 255.
Chris@70: * @param coupled_streams int: Number of streams to decode as coupled
Chris@70: * (2 channel) streams.
Chris@70: * This must be no larger than the total
Chris@70: * number of streams.
Chris@70: * Additionally, The total number of
Chris@70: * coded channels (streams +
Chris@70: * coupled_streams
) must be no
Chris@70: * more than 255.
Chris@70: * @param[in] mapping const unsigned char[channels]
: Mapping from
Chris@70: * coded channels to output channels, as described in
Chris@70: * @ref opus_multistream.
Chris@70: * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
Chris@70: * on failure.
Chris@70: */
Chris@70: OPUS_EXPORT int opus_multistream_decoder_init(
Chris@70: OpusMSDecoder *st,
Chris@70: opus_int32 Fs,
Chris@70: int channels,
Chris@70: int streams,
Chris@70: int coupled_streams,
Chris@70: const unsigned char *mapping
Chris@70: ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
Chris@70:
Chris@70: /** Decode a multistream Opus packet.
Chris@70: * @param st OpusMSDecoder*: Multistream decoder state.
Chris@70: * @param[in] data const unsigned char*: Input payload.
Chris@70: * Use a NULL
Chris@70: * pointer to indicate packet
Chris@70: * loss.
Chris@70: * @param len opus_int32: Number of bytes in payload.
Chris@70: * @param[out] pcm opus_int16*: Output signal, with interleaved
Chris@70: * samples.
Chris@70: * This must contain room for
Chris@70: * frame_size*channels
Chris@70: * samples.
Chris@70: * @param frame_size int: The number of samples per channel of
Chris@70: * available space in \a pcm.
Chris@70: * If this is less than the maximum packet duration
Chris@70: * (120 ms; 5760 for 48kHz), this function will not be capable
Chris@70: * of decoding some packets. In the case of PLC (data==NULL)
Chris@70: * or FEC (decode_fec=1), then frame_size needs to be exactly
Chris@70: * the duration of audio that is missing, otherwise the
Chris@70: * decoder will not be in the optimal state to decode the
Chris@70: * next incoming packet. For the PLC and FEC cases, frame_size
Chris@70: * must be a multiple of 2.5 ms.
Chris@70: * @param decode_fec int: Flag (0 or 1) to request that any in-band
Chris@70: * forward error correction data be decoded.
Chris@70: * If no such data is available, the frame is
Chris@70: * decoded as if it were lost.
Chris@70: * @returns Number of samples decoded on success or a negative error code
Chris@70: * (see @ref opus_errorcodes) on failure.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
Chris@70: OpusMSDecoder *st,
Chris@70: const unsigned char *data,
Chris@70: opus_int32 len,
Chris@70: opus_int16 *pcm,
Chris@70: int frame_size,
Chris@70: int decode_fec
Chris@70: ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
Chris@70:
Chris@70: /** Decode a multistream Opus packet with floating point output.
Chris@70: * @param st OpusMSDecoder*: Multistream decoder state.
Chris@70: * @param[in] data const unsigned char*: Input payload.
Chris@70: * Use a NULL
Chris@70: * pointer to indicate packet
Chris@70: * loss.
Chris@70: * @param len opus_int32: Number of bytes in payload.
Chris@70: * @param[out] pcm opus_int16*: Output signal, with interleaved
Chris@70: * samples.
Chris@70: * This must contain room for
Chris@70: * frame_size*channels
Chris@70: * samples.
Chris@70: * @param frame_size int: The number of samples per channel of
Chris@70: * available space in \a pcm.
Chris@70: * If this is less than the maximum packet duration
Chris@70: * (120 ms; 5760 for 48kHz), this function will not be capable
Chris@70: * of decoding some packets. In the case of PLC (data==NULL)
Chris@70: * or FEC (decode_fec=1), then frame_size needs to be exactly
Chris@70: * the duration of audio that is missing, otherwise the
Chris@70: * decoder will not be in the optimal state to decode the
Chris@70: * next incoming packet. For the PLC and FEC cases, frame_size
Chris@70: * must be a multiple of 2.5 ms.
Chris@70: * @param decode_fec int: Flag (0 or 1) to request that any in-band
Chris@70: * forward error correction data be decoded.
Chris@70: * If no such data is available, the frame is
Chris@70: * decoded as if it were lost.
Chris@70: * @returns Number of samples decoded on success or a negative error code
Chris@70: * (see @ref opus_errorcodes) on failure.
Chris@70: */
Chris@70: OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
Chris@70: OpusMSDecoder *st,
Chris@70: const unsigned char *data,
Chris@70: opus_int32 len,
Chris@70: float *pcm,
Chris@70: int frame_size,
Chris@70: int decode_fec
Chris@70: ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
Chris@70:
Chris@70: /** Perform a CTL function on a multistream Opus decoder.
Chris@70: *
Chris@70: * Generally the request and subsequent arguments are generated by a
Chris@70: * convenience macro.
Chris@70: * @param st OpusMSDecoder*: Multistream decoder state.
Chris@70: * @param request This and all remaining parameters should be replaced by one
Chris@70: * of the convenience macros in @ref opus_genericctls,
Chris@70: * @ref opus_decoderctls, or @ref opus_multistream_ctls.
Chris@70: * @see opus_genericctls
Chris@70: * @see opus_decoderctls
Chris@70: * @see opus_multistream_ctls
Chris@70: */
Chris@70: OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Chris@70:
Chris@70: /** Frees an OpusMSDecoder
allocated by
Chris@70: * opus_multistream_decoder_create().
Chris@70: * @param st OpusMSDecoder: Multistream decoder state to be freed.
Chris@70: */
Chris@70: OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
Chris@70:
Chris@70: /**@}*/
Chris@70:
Chris@70: /**@}*/
Chris@70:
Chris@70: #ifdef __cplusplus
Chris@70: }
Chris@70: #endif
Chris@70:
Chris@70: #endif /* OPUS_MULTISTREAM_H */