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