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