1*a58d3d2aSXin Li /* Copyright (c) 2011 Xiph.Org Foundation 2*a58d3d2aSXin Li Written by Jean-Marc Valin */ 3*a58d3d2aSXin Li /* 4*a58d3d2aSXin Li Redistribution and use in source and binary forms, with or without 5*a58d3d2aSXin Li modification, are permitted provided that the following conditions 6*a58d3d2aSXin Li are met: 7*a58d3d2aSXin Li 8*a58d3d2aSXin Li - Redistributions of source code must retain the above copyright 9*a58d3d2aSXin Li notice, this list of conditions and the following disclaimer. 10*a58d3d2aSXin Li 11*a58d3d2aSXin Li - Redistributions in binary form must reproduce the above copyright 12*a58d3d2aSXin Li notice, this list of conditions and the following disclaimer in the 13*a58d3d2aSXin Li documentation and/or other materials provided with the distribution. 14*a58d3d2aSXin Li 15*a58d3d2aSXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16*a58d3d2aSXin Li ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17*a58d3d2aSXin Li LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18*a58d3d2aSXin Li A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19*a58d3d2aSXin Li OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20*a58d3d2aSXin Li EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21*a58d3d2aSXin Li PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22*a58d3d2aSXin Li PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23*a58d3d2aSXin Li LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24*a58d3d2aSXin Li NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25*a58d3d2aSXin Li SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*a58d3d2aSXin Li */ 27*a58d3d2aSXin Li 28*a58d3d2aSXin Li /** 29*a58d3d2aSXin Li * @file opus_multistream.h 30*a58d3d2aSXin Li * @brief Opus reference implementation multistream API 31*a58d3d2aSXin Li */ 32*a58d3d2aSXin Li 33*a58d3d2aSXin Li #ifndef OPUS_MULTISTREAM_H 34*a58d3d2aSXin Li #define OPUS_MULTISTREAM_H 35*a58d3d2aSXin Li 36*a58d3d2aSXin Li #include "opus.h" 37*a58d3d2aSXin Li 38*a58d3d2aSXin Li #ifdef __cplusplus 39*a58d3d2aSXin Li extern "C" { 40*a58d3d2aSXin Li #endif 41*a58d3d2aSXin Li 42*a58d3d2aSXin Li /** @cond OPUS_INTERNAL_DOC */ 43*a58d3d2aSXin Li 44*a58d3d2aSXin Li /** Macros to trigger compilation errors when the wrong types are provided to a 45*a58d3d2aSXin Li * CTL. */ 46*a58d3d2aSXin Li /**@{*/ 47*a58d3d2aSXin Li #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) 48*a58d3d2aSXin Li #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) 49*a58d3d2aSXin Li /**@}*/ 50*a58d3d2aSXin Li 51*a58d3d2aSXin Li /** These are the actual encoder and decoder CTL ID numbers. 52*a58d3d2aSXin Li * They should not be used directly by applications. 53*a58d3d2aSXin Li * In general, SETs should be even and GETs should be odd.*/ 54*a58d3d2aSXin Li /**@{*/ 55*a58d3d2aSXin Li #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 56*a58d3d2aSXin Li #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 57*a58d3d2aSXin Li /**@}*/ 58*a58d3d2aSXin Li 59*a58d3d2aSXin Li /** @endcond */ 60*a58d3d2aSXin Li 61*a58d3d2aSXin Li /** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs 62*a58d3d2aSXin Li * 63*a58d3d2aSXin Li * These are convenience macros that are specific to the 64*a58d3d2aSXin Li * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() 65*a58d3d2aSXin Li * interface. 66*a58d3d2aSXin Li * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and 67*a58d3d2aSXin Li * @ref opus_decoderctls may be applied to a multistream encoder or decoder as 68*a58d3d2aSXin Li * well. 69*a58d3d2aSXin Li * In addition, you may retrieve the encoder or decoder state for an specific 70*a58d3d2aSXin Li * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or 71*a58d3d2aSXin Li * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. 72*a58d3d2aSXin Li */ 73*a58d3d2aSXin Li /**@{*/ 74*a58d3d2aSXin Li 75*a58d3d2aSXin Li /** Gets the encoder state for an individual stream of a multistream encoder. 76*a58d3d2aSXin Li * @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder you 77*a58d3d2aSXin Li * wish to retrieve. 78*a58d3d2aSXin Li * This must be non-negative and less than 79*a58d3d2aSXin Li * the <code>streams</code> parameter used 80*a58d3d2aSXin Li * to initialize the encoder. 81*a58d3d2aSXin Li * @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given 82*a58d3d2aSXin Li * encoder state. 83*a58d3d2aSXin Li * @retval OPUS_BAD_ARG The index of the requested stream was out of range. 84*a58d3d2aSXin Li * @hideinitializer 85*a58d3d2aSXin Li */ 86*a58d3d2aSXin Li #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) 87*a58d3d2aSXin Li 88*a58d3d2aSXin Li /** Gets the decoder state for an individual stream of a multistream decoder. 89*a58d3d2aSXin Li * @param[in] x <tt>opus_int32</tt>: The index of the stream whose decoder you 90*a58d3d2aSXin Li * wish to retrieve. 91*a58d3d2aSXin Li * This must be non-negative and less than 92*a58d3d2aSXin Li * the <code>streams</code> parameter used 93*a58d3d2aSXin Li * to initialize the decoder. 94*a58d3d2aSXin Li * @param[out] y <tt>OpusDecoder**</tt>: Returns a pointer to the given 95*a58d3d2aSXin Li * decoder state. 96*a58d3d2aSXin Li * @retval OPUS_BAD_ARG The index of the requested stream was out of range. 97*a58d3d2aSXin Li * @hideinitializer 98*a58d3d2aSXin Li */ 99*a58d3d2aSXin Li #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) 100*a58d3d2aSXin Li 101*a58d3d2aSXin Li /**@}*/ 102*a58d3d2aSXin Li 103*a58d3d2aSXin Li /** @defgroup opus_multistream Opus Multistream API 104*a58d3d2aSXin Li * @{ 105*a58d3d2aSXin Li * 106*a58d3d2aSXin Li * The multistream API allows individual Opus streams to be combined into a 107*a58d3d2aSXin Li * single packet, enabling support for up to 255 channels. Unlike an 108*a58d3d2aSXin Li * elementary Opus stream, the encoder and decoder must negotiate the channel 109*a58d3d2aSXin Li * configuration before the decoder can successfully interpret the data in the 110*a58d3d2aSXin Li * packets produced by the encoder. Some basic information, such as packet 111*a58d3d2aSXin Li * duration, can be computed without any special negotiation. 112*a58d3d2aSXin Li * 113*a58d3d2aSXin Li * The format for multistream Opus packets is defined in 114*a58d3d2aSXin Li * <a href="https://tools.ietf.org/html/rfc7845">RFC 7845</a> 115*a58d3d2aSXin Li * and is based on the self-delimited Opus framing described in Appendix B of 116*a58d3d2aSXin Li * <a href="https://tools.ietf.org/html/rfc6716">RFC 6716</a>. 117*a58d3d2aSXin Li * Normal Opus packets are just a degenerate case of multistream Opus packets, 118*a58d3d2aSXin Li * and can be encoded or decoded with the multistream API by setting 119*a58d3d2aSXin Li * <code>streams</code> to <code>1</code> when initializing the encoder or 120*a58d3d2aSXin Li * decoder. 121*a58d3d2aSXin Li * 122*a58d3d2aSXin Li * Multistream Opus streams can contain up to 255 elementary Opus streams. 123*a58d3d2aSXin Li * These may be either "uncoupled" or "coupled", indicating that the decoder 124*a58d3d2aSXin Li * is configured to decode them to either 1 or 2 channels, respectively. 125*a58d3d2aSXin Li * The streams are ordered so that all coupled streams appear at the 126*a58d3d2aSXin Li * beginning. 127*a58d3d2aSXin Li * 128*a58d3d2aSXin Li * A <code>mapping</code> table defines which decoded channel <code>i</code> 129*a58d3d2aSXin Li * should be used for each input/output (I/O) channel <code>j</code>. This table is 130*a58d3d2aSXin Li * typically provided as an unsigned char array. 131*a58d3d2aSXin Li * Let <code>i = mapping[j]</code> be the index for I/O channel <code>j</code>. 132*a58d3d2aSXin Li * If <code>i < 2*coupled_streams</code>, then I/O channel <code>j</code> is 133*a58d3d2aSXin Li * encoded as the left channel of stream <code>(i/2)</code> if <code>i</code> 134*a58d3d2aSXin Li * is even, or as the right channel of stream <code>(i/2)</code> if 135*a58d3d2aSXin Li * <code>i</code> is odd. Otherwise, I/O channel <code>j</code> is encoded as 136*a58d3d2aSXin Li * mono in stream <code>(i - coupled_streams)</code>, unless it has the special 137*a58d3d2aSXin Li * value 255, in which case it is omitted from the encoding entirely (the 138*a58d3d2aSXin Li * decoder will reproduce it as silence). Each value <code>i</code> must either 139*a58d3d2aSXin Li * be the special value 255 or be less than <code>streams + coupled_streams</code>. 140*a58d3d2aSXin Li * 141*a58d3d2aSXin Li * The output channels specified by the encoder 142*a58d3d2aSXin Li * should use the 143*a58d3d2aSXin Li * <a href="https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9">Vorbis 144*a58d3d2aSXin Li * channel ordering</a>. A decoder may wish to apply an additional permutation 145*a58d3d2aSXin Li * to the mapping the encoder used to achieve a different output channel 146*a58d3d2aSXin Li * order (e.g. for outputting in WAV order). 147*a58d3d2aSXin Li * 148*a58d3d2aSXin Li * Each multistream packet contains an Opus packet for each stream, and all of 149*a58d3d2aSXin Li * the Opus packets in a single multistream packet must have the same 150*a58d3d2aSXin Li * duration. Therefore the duration of a multistream packet can be extracted 151*a58d3d2aSXin Li * from the TOC sequence of the first stream, which is located at the 152*a58d3d2aSXin Li * beginning of the packet, just like an elementary Opus stream: 153*a58d3d2aSXin Li * 154*a58d3d2aSXin Li * @code 155*a58d3d2aSXin Li * int nb_samples; 156*a58d3d2aSXin Li * int nb_frames; 157*a58d3d2aSXin Li * nb_frames = opus_packet_get_nb_frames(data, len); 158*a58d3d2aSXin Li * if (nb_frames < 1) 159*a58d3d2aSXin Li * return nb_frames; 160*a58d3d2aSXin Li * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; 161*a58d3d2aSXin Li * @endcode 162*a58d3d2aSXin Li * 163*a58d3d2aSXin Li * The general encoding and decoding process proceeds exactly the same as in 164*a58d3d2aSXin Li * the normal @ref opus_encoder and @ref opus_decoder APIs. 165*a58d3d2aSXin Li * See their documentation for an overview of how to use the corresponding 166*a58d3d2aSXin Li * multistream functions. 167*a58d3d2aSXin Li */ 168*a58d3d2aSXin Li 169*a58d3d2aSXin Li /** Opus multistream encoder state. 170*a58d3d2aSXin Li * This contains the complete state of a multistream Opus encoder. 171*a58d3d2aSXin Li * It is position independent and can be freely copied. 172*a58d3d2aSXin Li * @see opus_multistream_encoder_create 173*a58d3d2aSXin Li * @see opus_multistream_encoder_init 174*a58d3d2aSXin Li */ 175*a58d3d2aSXin Li typedef struct OpusMSEncoder OpusMSEncoder; 176*a58d3d2aSXin Li 177*a58d3d2aSXin Li /** Opus multistream decoder state. 178*a58d3d2aSXin Li * This contains the complete state of a multistream Opus decoder. 179*a58d3d2aSXin Li * It is position independent and can be freely copied. 180*a58d3d2aSXin Li * @see opus_multistream_decoder_create 181*a58d3d2aSXin Li * @see opus_multistream_decoder_init 182*a58d3d2aSXin Li */ 183*a58d3d2aSXin Li typedef struct OpusMSDecoder OpusMSDecoder; 184*a58d3d2aSXin Li 185*a58d3d2aSXin Li /**\name Multistream encoder functions */ 186*a58d3d2aSXin Li /**@{*/ 187*a58d3d2aSXin Li 188*a58d3d2aSXin Li /** Gets the size of an OpusMSEncoder structure. 189*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams to encode from the 190*a58d3d2aSXin Li * input. 191*a58d3d2aSXin Li * This must be no more than 255. 192*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams 193*a58d3d2aSXin Li * to encode. 194*a58d3d2aSXin Li * This must be no larger than the total 195*a58d3d2aSXin Li * number of streams. 196*a58d3d2aSXin Li * Additionally, The total number of 197*a58d3d2aSXin Li * encoded channels (<code>streams + 198*a58d3d2aSXin Li * coupled_streams</code>) must be no 199*a58d3d2aSXin Li * more than 255. 200*a58d3d2aSXin Li * @returns The size in bytes on success, or a negative error code 201*a58d3d2aSXin Li * (see @ref opus_errorcodes) on error. 202*a58d3d2aSXin Li */ 203*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size( 204*a58d3d2aSXin Li int streams, 205*a58d3d2aSXin Li int coupled_streams 206*a58d3d2aSXin Li ); 207*a58d3d2aSXin Li 208*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size( 209*a58d3d2aSXin Li int channels, 210*a58d3d2aSXin Li int mapping_family 211*a58d3d2aSXin Li ); 212*a58d3d2aSXin Li 213*a58d3d2aSXin Li 214*a58d3d2aSXin Li /** Allocates and initializes a multistream encoder state. 215*a58d3d2aSXin Li * Call opus_multistream_encoder_destroy() to release 216*a58d3d2aSXin Li * this object when finished. 217*a58d3d2aSXin Li * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz). 218*a58d3d2aSXin Li * This must be one of 8000, 12000, 16000, 219*a58d3d2aSXin Li * 24000, or 48000. 220*a58d3d2aSXin Li * @param channels <tt>int</tt>: Number of channels in the input signal. 221*a58d3d2aSXin Li * This must be at most 255. 222*a58d3d2aSXin Li * It may be greater than the number of 223*a58d3d2aSXin Li * coded channels (<code>streams + 224*a58d3d2aSXin Li * coupled_streams</code>). 225*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams to encode from the 226*a58d3d2aSXin Li * input. 227*a58d3d2aSXin Li * This must be no more than the number of channels. 228*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams 229*a58d3d2aSXin Li * to encode. 230*a58d3d2aSXin Li * This must be no larger than the total 231*a58d3d2aSXin Li * number of streams. 232*a58d3d2aSXin Li * Additionally, The total number of 233*a58d3d2aSXin Li * encoded channels (<code>streams + 234*a58d3d2aSXin Li * coupled_streams</code>) must be no 235*a58d3d2aSXin Li * more than the number of input channels. 236*a58d3d2aSXin Li * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from 237*a58d3d2aSXin Li * encoded channels to input channels, as described in 238*a58d3d2aSXin Li * @ref opus_multistream. As an extra constraint, the 239*a58d3d2aSXin Li * multistream encoder does not allow encoding coupled 240*a58d3d2aSXin Li * streams for which one channel is unused since this 241*a58d3d2aSXin Li * is never a good idea. 242*a58d3d2aSXin Li * @param application <tt>int</tt>: The target encoder application. 243*a58d3d2aSXin Li * This must be one of the following: 244*a58d3d2aSXin Li * <dl> 245*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_VOIP</dt> 246*a58d3d2aSXin Li * <dd>Process signal for improved speech intelligibility.</dd> 247*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_AUDIO</dt> 248*a58d3d2aSXin Li * <dd>Favor faithfulness to the original input.</dd> 249*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> 250*a58d3d2aSXin Li * <dd>Configure the minimum possible coding delay by disabling certain modes 251*a58d3d2aSXin Li * of operation.</dd> 252*a58d3d2aSXin Li * </dl> 253*a58d3d2aSXin Li * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error 254*a58d3d2aSXin Li * code (see @ref opus_errorcodes) on 255*a58d3d2aSXin Li * failure. 256*a58d3d2aSXin Li */ 257*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create( 258*a58d3d2aSXin Li opus_int32 Fs, 259*a58d3d2aSXin Li int channels, 260*a58d3d2aSXin Li int streams, 261*a58d3d2aSXin Li int coupled_streams, 262*a58d3d2aSXin Li const unsigned char *mapping, 263*a58d3d2aSXin Li int application, 264*a58d3d2aSXin Li int *error 265*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(5); 266*a58d3d2aSXin Li 267*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create( 268*a58d3d2aSXin Li opus_int32 Fs, 269*a58d3d2aSXin Li int channels, 270*a58d3d2aSXin Li int mapping_family, 271*a58d3d2aSXin Li int *streams, 272*a58d3d2aSXin Li int *coupled_streams, 273*a58d3d2aSXin Li unsigned char *mapping, 274*a58d3d2aSXin Li int application, 275*a58d3d2aSXin Li int *error 276*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); 277*a58d3d2aSXin Li 278*a58d3d2aSXin Li /** Initialize a previously allocated multistream encoder state. 279*a58d3d2aSXin Li * The memory pointed to by \a st must be at least the size returned by 280*a58d3d2aSXin Li * opus_multistream_encoder_get_size(). 281*a58d3d2aSXin Li * This is intended for applications which use their own allocator instead of 282*a58d3d2aSXin Li * malloc. 283*a58d3d2aSXin Li * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. 284*a58d3d2aSXin Li * @see opus_multistream_encoder_create 285*a58d3d2aSXin Li * @see opus_multistream_encoder_get_size 286*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize. 287*a58d3d2aSXin Li * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz). 288*a58d3d2aSXin Li * This must be one of 8000, 12000, 16000, 289*a58d3d2aSXin Li * 24000, or 48000. 290*a58d3d2aSXin Li * @param channels <tt>int</tt>: Number of channels in the input signal. 291*a58d3d2aSXin Li * This must be at most 255. 292*a58d3d2aSXin Li * It may be greater than the number of 293*a58d3d2aSXin Li * coded channels (<code>streams + 294*a58d3d2aSXin Li * coupled_streams</code>). 295*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams to encode from the 296*a58d3d2aSXin Li * input. 297*a58d3d2aSXin Li * This must be no more than the number of channels. 298*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams 299*a58d3d2aSXin Li * to encode. 300*a58d3d2aSXin Li * This must be no larger than the total 301*a58d3d2aSXin Li * number of streams. 302*a58d3d2aSXin Li * Additionally, The total number of 303*a58d3d2aSXin Li * encoded channels (<code>streams + 304*a58d3d2aSXin Li * coupled_streams</code>) must be no 305*a58d3d2aSXin Li * more than the number of input channels. 306*a58d3d2aSXin Li * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from 307*a58d3d2aSXin Li * encoded channels to input channels, as described in 308*a58d3d2aSXin Li * @ref opus_multistream. As an extra constraint, the 309*a58d3d2aSXin Li * multistream encoder does not allow encoding coupled 310*a58d3d2aSXin Li * streams for which one channel is unused since this 311*a58d3d2aSXin Li * is never a good idea. 312*a58d3d2aSXin Li * @param application <tt>int</tt>: The target encoder application. 313*a58d3d2aSXin Li * This must be one of the following: 314*a58d3d2aSXin Li * <dl> 315*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_VOIP</dt> 316*a58d3d2aSXin Li * <dd>Process signal for improved speech intelligibility.</dd> 317*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_AUDIO</dt> 318*a58d3d2aSXin Li * <dd>Favor faithfulness to the original input.</dd> 319*a58d3d2aSXin Li * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> 320*a58d3d2aSXin Li * <dd>Configure the minimum possible coding delay by disabling certain modes 321*a58d3d2aSXin Li * of operation.</dd> 322*a58d3d2aSXin Li * </dl> 323*a58d3d2aSXin Li * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) 324*a58d3d2aSXin Li * on failure. 325*a58d3d2aSXin Li */ 326*a58d3d2aSXin Li OPUS_EXPORT int opus_multistream_encoder_init( 327*a58d3d2aSXin Li OpusMSEncoder *st, 328*a58d3d2aSXin Li opus_int32 Fs, 329*a58d3d2aSXin Li int channels, 330*a58d3d2aSXin Li int streams, 331*a58d3d2aSXin Li int coupled_streams, 332*a58d3d2aSXin Li const unsigned char *mapping, 333*a58d3d2aSXin Li int application 334*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); 335*a58d3d2aSXin Li 336*a58d3d2aSXin Li OPUS_EXPORT int opus_multistream_surround_encoder_init( 337*a58d3d2aSXin Li OpusMSEncoder *st, 338*a58d3d2aSXin Li opus_int32 Fs, 339*a58d3d2aSXin Li int channels, 340*a58d3d2aSXin Li int mapping_family, 341*a58d3d2aSXin Li int *streams, 342*a58d3d2aSXin Li int *coupled_streams, 343*a58d3d2aSXin Li unsigned char *mapping, 344*a58d3d2aSXin Li int application 345*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); 346*a58d3d2aSXin Li 347*a58d3d2aSXin Li /** Encodes a multistream Opus frame. 348*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. 349*a58d3d2aSXin Li * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved 350*a58d3d2aSXin Li * samples. 351*a58d3d2aSXin Li * This must contain 352*a58d3d2aSXin Li * <code>frame_size*channels</code> 353*a58d3d2aSXin Li * samples. 354*a58d3d2aSXin Li * @param frame_size <tt>int</tt>: Number of samples per channel in the input 355*a58d3d2aSXin Li * signal. 356*a58d3d2aSXin Li * This must be an Opus frame size for the 357*a58d3d2aSXin Li * encoder's sampling rate. 358*a58d3d2aSXin Li * For example, at 48 kHz the permitted values 359*a58d3d2aSXin Li * are 120, 240, 480, 960, 1920, and 2880. 360*a58d3d2aSXin Li * Passing in a duration of less than 10 ms 361*a58d3d2aSXin Li * (480 samples at 48 kHz) will prevent the 362*a58d3d2aSXin Li * encoder from using the LPC or hybrid modes. 363*a58d3d2aSXin Li * @param[out] data <tt>unsigned char*</tt>: Output payload. 364*a58d3d2aSXin Li * This must contain storage for at 365*a58d3d2aSXin Li * least \a max_data_bytes. 366*a58d3d2aSXin Li * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated 367*a58d3d2aSXin Li * memory for the output 368*a58d3d2aSXin Li * payload. This may be 369*a58d3d2aSXin Li * used to impose an upper limit on 370*a58d3d2aSXin Li * the instant bitrate, but should 371*a58d3d2aSXin Li * not be used as the only bitrate 372*a58d3d2aSXin Li * control. Use #OPUS_SET_BITRATE to 373*a58d3d2aSXin Li * control the bitrate. 374*a58d3d2aSXin Li * @returns The length of the encoded packet (in bytes) on success or a 375*a58d3d2aSXin Li * negative error code (see @ref opus_errorcodes) on failure. 376*a58d3d2aSXin Li */ 377*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( 378*a58d3d2aSXin Li OpusMSEncoder *st, 379*a58d3d2aSXin Li const opus_int16 *pcm, 380*a58d3d2aSXin Li int frame_size, 381*a58d3d2aSXin Li unsigned char *data, 382*a58d3d2aSXin Li opus_int32 max_data_bytes 383*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); 384*a58d3d2aSXin Li 385*a58d3d2aSXin Li /** Encodes a multistream Opus frame from floating point input. 386*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. 387*a58d3d2aSXin Li * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved 388*a58d3d2aSXin Li * samples with a normal range of 389*a58d3d2aSXin Li * +/-1.0. 390*a58d3d2aSXin Li * Samples with a range beyond +/-1.0 391*a58d3d2aSXin Li * are supported but will be clipped by 392*a58d3d2aSXin Li * decoders using the integer API and 393*a58d3d2aSXin Li * should only be used if it is known 394*a58d3d2aSXin Li * that the far end supports extended 395*a58d3d2aSXin Li * dynamic range. 396*a58d3d2aSXin Li * This must contain 397*a58d3d2aSXin Li * <code>frame_size*channels</code> 398*a58d3d2aSXin Li * samples. 399*a58d3d2aSXin Li * @param frame_size <tt>int</tt>: Number of samples per channel in the input 400*a58d3d2aSXin Li * signal. 401*a58d3d2aSXin Li * This must be an Opus frame size for the 402*a58d3d2aSXin Li * encoder's sampling rate. 403*a58d3d2aSXin Li * For example, at 48 kHz the permitted values 404*a58d3d2aSXin Li * are 120, 240, 480, 960, 1920, and 2880. 405*a58d3d2aSXin Li * Passing in a duration of less than 10 ms 406*a58d3d2aSXin Li * (480 samples at 48 kHz) will prevent the 407*a58d3d2aSXin Li * encoder from using the LPC or hybrid modes. 408*a58d3d2aSXin Li * @param[out] data <tt>unsigned char*</tt>: Output payload. 409*a58d3d2aSXin Li * This must contain storage for at 410*a58d3d2aSXin Li * least \a max_data_bytes. 411*a58d3d2aSXin Li * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated 412*a58d3d2aSXin Li * memory for the output 413*a58d3d2aSXin Li * payload. This may be 414*a58d3d2aSXin Li * used to impose an upper limit on 415*a58d3d2aSXin Li * the instant bitrate, but should 416*a58d3d2aSXin Li * not be used as the only bitrate 417*a58d3d2aSXin Li * control. Use #OPUS_SET_BITRATE to 418*a58d3d2aSXin Li * control the bitrate. 419*a58d3d2aSXin Li * @returns The length of the encoded packet (in bytes) on success or a 420*a58d3d2aSXin Li * negative error code (see @ref opus_errorcodes) on failure. 421*a58d3d2aSXin Li */ 422*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( 423*a58d3d2aSXin Li OpusMSEncoder *st, 424*a58d3d2aSXin Li const float *pcm, 425*a58d3d2aSXin Li int frame_size, 426*a58d3d2aSXin Li unsigned char *data, 427*a58d3d2aSXin Li opus_int32 max_data_bytes 428*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); 429*a58d3d2aSXin Li 430*a58d3d2aSXin Li /** Frees an <code>OpusMSEncoder</code> allocated by 431*a58d3d2aSXin Li * opus_multistream_encoder_create(). 432*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed. 433*a58d3d2aSXin Li */ 434*a58d3d2aSXin Li OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); 435*a58d3d2aSXin Li 436*a58d3d2aSXin Li /** Perform a CTL function on a multistream Opus encoder. 437*a58d3d2aSXin Li * 438*a58d3d2aSXin Li * Generally the request and subsequent arguments are generated by a 439*a58d3d2aSXin Li * convenience macro. 440*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. 441*a58d3d2aSXin Li * @param request This and all remaining parameters should be replaced by one 442*a58d3d2aSXin Li * of the convenience macros in @ref opus_genericctls, 443*a58d3d2aSXin Li * @ref opus_encoderctls, or @ref opus_multistream_ctls. 444*a58d3d2aSXin Li * @see opus_genericctls 445*a58d3d2aSXin Li * @see opus_encoderctls 446*a58d3d2aSXin Li * @see opus_multistream_ctls 447*a58d3d2aSXin Li */ 448*a58d3d2aSXin Li OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); 449*a58d3d2aSXin Li 450*a58d3d2aSXin Li /**@}*/ 451*a58d3d2aSXin Li 452*a58d3d2aSXin Li /**\name Multistream decoder functions */ 453*a58d3d2aSXin Li /**@{*/ 454*a58d3d2aSXin Li 455*a58d3d2aSXin Li /** Gets the size of an <code>OpusMSDecoder</code> structure. 456*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams coded in the 457*a58d3d2aSXin Li * input. 458*a58d3d2aSXin Li * This must be no more than 255. 459*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled 460*a58d3d2aSXin Li * (2 channel) streams. 461*a58d3d2aSXin Li * This must be no larger than the total 462*a58d3d2aSXin Li * number of streams. 463*a58d3d2aSXin Li * Additionally, The total number of 464*a58d3d2aSXin Li * coded channels (<code>streams + 465*a58d3d2aSXin Li * coupled_streams</code>) must be no 466*a58d3d2aSXin Li * more than 255. 467*a58d3d2aSXin Li * @returns The size in bytes on success, or a negative error code 468*a58d3d2aSXin Li * (see @ref opus_errorcodes) on error. 469*a58d3d2aSXin Li */ 470*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size( 471*a58d3d2aSXin Li int streams, 472*a58d3d2aSXin Li int coupled_streams 473*a58d3d2aSXin Li ); 474*a58d3d2aSXin Li 475*a58d3d2aSXin Li /** Allocates and initializes a multistream decoder state. 476*a58d3d2aSXin Li * Call opus_multistream_decoder_destroy() to release 477*a58d3d2aSXin Li * this object when finished. 478*a58d3d2aSXin Li * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz). 479*a58d3d2aSXin Li * This must be one of 8000, 12000, 16000, 480*a58d3d2aSXin Li * 24000, or 48000. 481*a58d3d2aSXin Li * @param channels <tt>int</tt>: Number of channels to output. 482*a58d3d2aSXin Li * This must be at most 255. 483*a58d3d2aSXin Li * It may be different from the number of coded 484*a58d3d2aSXin Li * channels (<code>streams + 485*a58d3d2aSXin Li * coupled_streams</code>). 486*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams coded in the 487*a58d3d2aSXin Li * input. 488*a58d3d2aSXin Li * This must be no more than 255. 489*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled 490*a58d3d2aSXin Li * (2 channel) streams. 491*a58d3d2aSXin Li * This must be no larger than the total 492*a58d3d2aSXin Li * number of streams. 493*a58d3d2aSXin Li * Additionally, The total number of 494*a58d3d2aSXin Li * coded channels (<code>streams + 495*a58d3d2aSXin Li * coupled_streams</code>) must be no 496*a58d3d2aSXin Li * more than 255. 497*a58d3d2aSXin Li * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from 498*a58d3d2aSXin Li * coded channels to output channels, as described in 499*a58d3d2aSXin Li * @ref opus_multistream. 500*a58d3d2aSXin Li * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error 501*a58d3d2aSXin Li * code (see @ref opus_errorcodes) on 502*a58d3d2aSXin Li * failure. 503*a58d3d2aSXin Li */ 504*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create( 505*a58d3d2aSXin Li opus_int32 Fs, 506*a58d3d2aSXin Li int channels, 507*a58d3d2aSXin Li int streams, 508*a58d3d2aSXin Li int coupled_streams, 509*a58d3d2aSXin Li const unsigned char *mapping, 510*a58d3d2aSXin Li int *error 511*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(5); 512*a58d3d2aSXin Li 513*a58d3d2aSXin Li /** Intialize a previously allocated decoder state object. 514*a58d3d2aSXin Li * The memory pointed to by \a st must be at least the size returned by 515*a58d3d2aSXin Li * opus_multistream_encoder_get_size(). 516*a58d3d2aSXin Li * This is intended for applications which use their own allocator instead of 517*a58d3d2aSXin Li * malloc. 518*a58d3d2aSXin Li * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. 519*a58d3d2aSXin Li * @see opus_multistream_decoder_create 520*a58d3d2aSXin Li * @see opus_multistream_deocder_get_size 521*a58d3d2aSXin Li * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize. 522*a58d3d2aSXin Li * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz). 523*a58d3d2aSXin Li * This must be one of 8000, 12000, 16000, 524*a58d3d2aSXin Li * 24000, or 48000. 525*a58d3d2aSXin Li * @param channels <tt>int</tt>: Number of channels to output. 526*a58d3d2aSXin Li * This must be at most 255. 527*a58d3d2aSXin Li * It may be different from the number of coded 528*a58d3d2aSXin Li * channels (<code>streams + 529*a58d3d2aSXin Li * coupled_streams</code>). 530*a58d3d2aSXin Li * @param streams <tt>int</tt>: The total number of streams coded in the 531*a58d3d2aSXin Li * input. 532*a58d3d2aSXin Li * This must be no more than 255. 533*a58d3d2aSXin Li * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled 534*a58d3d2aSXin Li * (2 channel) streams. 535*a58d3d2aSXin Li * This must be no larger than the total 536*a58d3d2aSXin Li * number of streams. 537*a58d3d2aSXin Li * Additionally, The total number of 538*a58d3d2aSXin Li * coded channels (<code>streams + 539*a58d3d2aSXin Li * coupled_streams</code>) must be no 540*a58d3d2aSXin Li * more than 255. 541*a58d3d2aSXin Li * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from 542*a58d3d2aSXin Li * coded channels to output channels, as described in 543*a58d3d2aSXin Li * @ref opus_multistream. 544*a58d3d2aSXin Li * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) 545*a58d3d2aSXin Li * on failure. 546*a58d3d2aSXin Li */ 547*a58d3d2aSXin Li OPUS_EXPORT int opus_multistream_decoder_init( 548*a58d3d2aSXin Li OpusMSDecoder *st, 549*a58d3d2aSXin Li opus_int32 Fs, 550*a58d3d2aSXin Li int channels, 551*a58d3d2aSXin Li int streams, 552*a58d3d2aSXin Li int coupled_streams, 553*a58d3d2aSXin Li const unsigned char *mapping 554*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); 555*a58d3d2aSXin Li 556*a58d3d2aSXin Li /** Decode a multistream Opus packet. 557*a58d3d2aSXin Li * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. 558*a58d3d2aSXin Li * @param[in] data <tt>const unsigned char*</tt>: Input payload. 559*a58d3d2aSXin Li * Use a <code>NULL</code> 560*a58d3d2aSXin Li * pointer to indicate packet 561*a58d3d2aSXin Li * loss. 562*a58d3d2aSXin Li * @param len <tt>opus_int32</tt>: Number of bytes in payload. 563*a58d3d2aSXin Li * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved 564*a58d3d2aSXin Li * samples. 565*a58d3d2aSXin Li * This must contain room for 566*a58d3d2aSXin Li * <code>frame_size*channels</code> 567*a58d3d2aSXin Li * samples. 568*a58d3d2aSXin Li * @param frame_size <tt>int</tt>: The number of samples per channel of 569*a58d3d2aSXin Li * available space in \a pcm. 570*a58d3d2aSXin Li * If this is less than the maximum packet duration 571*a58d3d2aSXin Li * (120 ms; 5760 for 48kHz), this function will not be capable 572*a58d3d2aSXin Li * of decoding some packets. In the case of PLC (data==NULL) 573*a58d3d2aSXin Li * or FEC (decode_fec=1), then frame_size needs to be exactly 574*a58d3d2aSXin Li * the duration of audio that is missing, otherwise the 575*a58d3d2aSXin Li * decoder will not be in the optimal state to decode the 576*a58d3d2aSXin Li * next incoming packet. For the PLC and FEC cases, frame_size 577*a58d3d2aSXin Li * <b>must</b> be a multiple of 2.5 ms. 578*a58d3d2aSXin Li * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band 579*a58d3d2aSXin Li * forward error correction data be decoded. 580*a58d3d2aSXin Li * If no such data is available, the frame is 581*a58d3d2aSXin Li * decoded as if it were lost. 582*a58d3d2aSXin Li * @returns Number of samples decoded on success or a negative error code 583*a58d3d2aSXin Li * (see @ref opus_errorcodes) on failure. 584*a58d3d2aSXin Li */ 585*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( 586*a58d3d2aSXin Li OpusMSDecoder *st, 587*a58d3d2aSXin Li const unsigned char *data, 588*a58d3d2aSXin Li opus_int32 len, 589*a58d3d2aSXin Li opus_int16 *pcm, 590*a58d3d2aSXin Li int frame_size, 591*a58d3d2aSXin Li int decode_fec 592*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); 593*a58d3d2aSXin Li 594*a58d3d2aSXin Li /** Decode a multistream Opus packet with floating point output. 595*a58d3d2aSXin Li * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. 596*a58d3d2aSXin Li * @param[in] data <tt>const unsigned char*</tt>: Input payload. 597*a58d3d2aSXin Li * Use a <code>NULL</code> 598*a58d3d2aSXin Li * pointer to indicate packet 599*a58d3d2aSXin Li * loss. 600*a58d3d2aSXin Li * @param len <tt>opus_int32</tt>: Number of bytes in payload. 601*a58d3d2aSXin Li * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved 602*a58d3d2aSXin Li * samples. 603*a58d3d2aSXin Li * This must contain room for 604*a58d3d2aSXin Li * <code>frame_size*channels</code> 605*a58d3d2aSXin Li * samples. 606*a58d3d2aSXin Li * @param frame_size <tt>int</tt>: The number of samples per channel of 607*a58d3d2aSXin Li * available space in \a pcm. 608*a58d3d2aSXin Li * If this is less than the maximum packet duration 609*a58d3d2aSXin Li * (120 ms; 5760 for 48kHz), this function will not be capable 610*a58d3d2aSXin Li * of decoding some packets. In the case of PLC (data==NULL) 611*a58d3d2aSXin Li * or FEC (decode_fec=1), then frame_size needs to be exactly 612*a58d3d2aSXin Li * the duration of audio that is missing, otherwise the 613*a58d3d2aSXin Li * decoder will not be in the optimal state to decode the 614*a58d3d2aSXin Li * next incoming packet. For the PLC and FEC cases, frame_size 615*a58d3d2aSXin Li * <b>must</b> be a multiple of 2.5 ms. 616*a58d3d2aSXin Li * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band 617*a58d3d2aSXin Li * forward error correction data be decoded. 618*a58d3d2aSXin Li * If no such data is available, the frame is 619*a58d3d2aSXin Li * decoded as if it were lost. 620*a58d3d2aSXin Li * @returns Number of samples decoded on success or a negative error code 621*a58d3d2aSXin Li * (see @ref opus_errorcodes) on failure. 622*a58d3d2aSXin Li */ 623*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( 624*a58d3d2aSXin Li OpusMSDecoder *st, 625*a58d3d2aSXin Li const unsigned char *data, 626*a58d3d2aSXin Li opus_int32 len, 627*a58d3d2aSXin Li float *pcm, 628*a58d3d2aSXin Li int frame_size, 629*a58d3d2aSXin Li int decode_fec 630*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); 631*a58d3d2aSXin Li 632*a58d3d2aSXin Li /** Perform a CTL function on a multistream Opus decoder. 633*a58d3d2aSXin Li * 634*a58d3d2aSXin Li * Generally the request and subsequent arguments are generated by a 635*a58d3d2aSXin Li * convenience macro. 636*a58d3d2aSXin Li * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. 637*a58d3d2aSXin Li * @param request This and all remaining parameters should be replaced by one 638*a58d3d2aSXin Li * of the convenience macros in @ref opus_genericctls, 639*a58d3d2aSXin Li * @ref opus_decoderctls, or @ref opus_multistream_ctls. 640*a58d3d2aSXin Li * @see opus_genericctls 641*a58d3d2aSXin Li * @see opus_decoderctls 642*a58d3d2aSXin Li * @see opus_multistream_ctls 643*a58d3d2aSXin Li */ 644*a58d3d2aSXin Li OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); 645*a58d3d2aSXin Li 646*a58d3d2aSXin Li /** Frees an <code>OpusMSDecoder</code> allocated by 647*a58d3d2aSXin Li * opus_multistream_decoder_create(). 648*a58d3d2aSXin Li * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed. 649*a58d3d2aSXin Li */ 650*a58d3d2aSXin Li OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); 651*a58d3d2aSXin Li 652*a58d3d2aSXin Li /**@}*/ 653*a58d3d2aSXin Li 654*a58d3d2aSXin Li /**@}*/ 655*a58d3d2aSXin Li 656*a58d3d2aSXin Li #ifdef __cplusplus 657*a58d3d2aSXin Li } 658*a58d3d2aSXin Li #endif 659*a58d3d2aSXin Li 660*a58d3d2aSXin Li #endif /* OPUS_MULTISTREAM_H */ 661