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