blob: 658067f7f1c579bd67542cfe3468ee5d47548aca [file] [log] [blame]
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +00001/* 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
39extern "C" {
40#endif
41
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000042/** @cond OPUS_INTERNAL_DOC */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000043
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000044/** Macros to trigger compilation errors when the wrong types are provided to a
45 * CTL. */
46/**@{*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000047#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
48#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000049/**@}*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000050
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000051/** 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/**@{*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000055#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
56#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000057/**@}*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000058
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000059/** @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 */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000086#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +000087
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 */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000099#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
100
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000101/**@}*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000102
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000103/** @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 the
114 * <a href="http://tools.ietf.org/html/draft-terriberry-oggopus">Ogg
115 * encapsulation specification</a> and is based on the self-delimited Opus
116 * framing described in Appendix B of <a href="http://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="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.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 */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000168
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000169/** 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 */
175typedef struct OpusMSEncoder OpusMSEncoder;
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000176
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000177/** 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 */
183typedef struct OpusMSDecoder OpusMSDecoder;
184
185/**\name Multistream encoder functions */
186/**@{*/
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000187
188/** Gets the size of an OpusMSEncoder structure.
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000189 * @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.
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000202 */
203OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000204 int streams,
205 int coupled_streams
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000206);
207
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000208/** Allocates and initializes a multistream encoder state.
209 * Call opus_multistream_encoder_destroy() to release
210 * this object when finished.
211 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
212 * This must be one of 8000, 12000, 16000,
213 * 24000, or 48000.
214 * @param channels <tt>int</tt>: Number of channels in the input signal.
215 * This must be at most 255.
216 * It may be greater than the number of
217 * coded channels (<code>streams +
218 * coupled_streams</code>).
219 * @param streams <tt>int</tt>: The total number of streams to encode from the
220 * input.
221 * This must be no more than the number of channels.
222 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
223 * to encode.
224 * This must be no larger than the total
225 * number of streams.
226 * Additionally, The total number of
227 * encoded channels (<code>streams +
228 * coupled_streams</code>) must be no
229 * more than the number of input channels.
230 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
231 * encoded channels to input channels, as described in
232 * @ref opus_multistream. As an extra constraint, the
233 * multistream encoder does not allow encoding coupled
234 * streams for which one channel is unused since this
235 * is never a good idea.
236 * @param application <tt>int</tt>: The target encoder application.
237 * This must be one of the following:
238 * <dl>
239 * <dt>#OPUS_APPLICATION_VOIP</dt>
240 * <dd>Process signal for improved speech intelligibility.</dd>
241 * <dt>#OPUS_APPLICATION_AUDIO</dt>
242 * <dd>Favor faithfulness to the original input.</dd>
243 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
244 * <dd>Configure the minimum possible coding delay by disabling certain modes
245 * of operation.</dd>
246 * </dl>
247 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
248 * code (see @ref opus_errorcodes) on
249 * failure.
250 */
251OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
252 opus_int32 Fs,
253 int channels,
254 int streams,
255 int coupled_streams,
256 const unsigned char *mapping,
257 int application,
258 int *error
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000259) OPUS_ARG_NONNULL(5);
260
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000261/** Initialize a previously allocated multistream encoder state.
262 * The memory pointed to by \a st must be at least the size returned by
263 * opus_multistream_encoder_get_size().
264 * This is intended for applications which use their own allocator instead of
265 * malloc.
266 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
267 * @see opus_multistream_encoder_create
268 * @see opus_multistream_encoder_get_size
269 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
270 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
271 * This must be one of 8000, 12000, 16000,
272 * 24000, or 48000.
273 * @param channels <tt>int</tt>: Number of channels in the input signal.
274 * This must be at most 255.
275 * It may be greater than the number of
276 * coded channels (<code>streams +
277 * coupled_streams</code>).
278 * @param streams <tt>int</tt>: The total number of streams to encode from the
279 * input.
280 * This must be no more than the number of channels.
281 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
282 * to encode.
283 * This must be no larger than the total
284 * number of streams.
285 * Additionally, The total number of
286 * encoded channels (<code>streams +
287 * coupled_streams</code>) must be no
288 * more than the number of input channels.
289 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
290 * encoded channels to input channels, as described in
291 * @ref opus_multistream. As an extra constraint, the
292 * multistream encoder does not allow encoding coupled
293 * streams for which one channel is unused since this
294 * is never a good idea.
295 * @param application <tt>int</tt>: The target encoder application.
296 * This must be one of the following:
297 * <dl>
298 * <dt>#OPUS_APPLICATION_VOIP</dt>
299 * <dd>Process signal for improved speech intelligibility.</dd>
300 * <dt>#OPUS_APPLICATION_AUDIO</dt>
301 * <dd>Favor faithfulness to the original input.</dd>
302 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
303 * <dd>Configure the minimum possible coding delay by disabling certain modes
304 * of operation.</dd>
305 * </dl>
306 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
307 * on failure.
308 */
309OPUS_EXPORT int opus_multistream_encoder_init(
310 OpusMSEncoder *st,
311 opus_int32 Fs,
312 int channels,
313 int streams,
314 int coupled_streams,
315 const unsigned char *mapping,
316 int application
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000317) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
318
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000319/** Encodes a multistream Opus frame.
320 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
321 * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
322 * samples.
323 * This must contain
324 * <code>frame_size*channels</code>
325 * samples.
326 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
327 * signal.
328 * This must be an Opus frame size for the
329 * encoder's sampling rate.
330 * For example, at 48 kHz the permitted values
331 * are 120, 240, 480, 960, 1920, and 2880.
332 * Passing in a duration of less than 10 ms
333 * (480 samples at 48 kHz) will prevent the
334 * encoder from using the LPC or hybrid modes.
335 * @param[out] data <tt>unsigned char*</tt>: Output payload.
336 * This must contain storage for at
337 * least \a max_data_bytes.
338 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
339 * memory for the output
340 * payload. This may be
341 * used to impose an upper limit on
342 * the instant bitrate, but should
343 * not be used as the only bitrate
344 * control. Use #OPUS_SET_BITRATE to
345 * control the bitrate.
346 * @returns The length of the encoded packet (in bytes) on success or a
347 * negative error code (see @ref opus_errorcodes) on failure.
348 */
349OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
350 OpusMSEncoder *st,
351 const opus_int16 *pcm,
352 int frame_size,
353 unsigned char *data,
354 opus_int32 max_data_bytes
355) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000356
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000357/** Encodes a multistream Opus frame from floating point input.
358 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
359 * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
360 * samples with a normal range of
361 * +/-1.0.
362 * Samples with a range beyond +/-1.0
363 * are supported but will be clipped by
364 * decoders using the integer API and
365 * should only be used if it is known
366 * that the far end supports extended
367 * dynamic range.
368 * This must contain
369 * <code>frame_size*channels</code>
370 * samples.
371 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
372 * signal.
373 * This must be an Opus frame size for the
374 * encoder's sampling rate.
375 * For example, at 48 kHz the permitted values
376 * are 120, 240, 480, 960, 1920, and 2880.
377 * Passing in a duration of less than 10 ms
378 * (480 samples at 48 kHz) will prevent the
379 * encoder from using the LPC or hybrid modes.
380 * @param[out] data <tt>unsigned char*</tt>: Output payload.
381 * This must contain storage for at
382 * least \a max_data_bytes.
383 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
384 * memory for the output
385 * payload. This may be
386 * used to impose an upper limit on
387 * the instant bitrate, but should
388 * not be used as the only bitrate
389 * control. Use #OPUS_SET_BITRATE to
390 * control the bitrate.
391 * @returns The length of the encoded packet (in bytes) on success or a
392 * negative error code (see @ref opus_errorcodes) on failure.
393 */
394OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
395 OpusMSEncoder *st,
396 const float *pcm,
397 int frame_size,
398 unsigned char *data,
399 opus_int32 max_data_bytes
400) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000401
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000402/** Frees an <code>OpusMSEncoder</code> allocated by
403 * opus_multistream_encoder_create().
404 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
405 */
406OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
407
408/** Perform a CTL function on a multistream Opus encoder.
409 *
410 * Generally the request and subsequent arguments are generated by a
411 * convenience macro.
412 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
413 * @param request This and all remaining parameters should be replaced by one
414 * of the convenience macros in @ref opus_genericctls,
415 * @ref opus_encoderctls, or @ref opus_multistream_ctls.
416 * @see opus_genericctls
417 * @see opus_encoderctls
418 * @see opus_multistream_ctls
419 */
420OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
421
422/**@}*/
423
424/**\name Multistream decoder functions */
425/**@{*/
426
427/** Gets the size of an <code>OpusMSDecoder</code> structure.
428 * @param streams <tt>int</tt>: The total number of streams coded in the
429 * input.
430 * This must be no more than 255.
431 * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
432 * (2 channel) streams.
433 * This must be no larger than the total
434 * number of streams.
435 * Additionally, The total number of
436 * coded channels (<code>streams +
437 * coupled_streams</code>) must be no
438 * more than 255.
439 * @returns The size in bytes on success, or a negative error code
440 * (see @ref opus_errorcodes) on error.
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000441 */
442OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000443 int streams,
444 int coupled_streams
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000445);
446
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000447/** Allocates and initializes a multistream decoder state.
448 * Call opus_multistream_decoder_destroy() to release
449 * this object when finished.
450 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
451 * This must be one of 8000, 12000, 16000,
452 * 24000, or 48000.
453 * @param channels <tt>int</tt>: Number of channels to output.
454 * This must be at most 255.
455 * It may be different from the number of coded
456 * channels (<code>streams +
457 * coupled_streams</code>).
458 * @param streams <tt>int</tt>: The total number of streams coded in the
459 * input.
460 * This must be no more than 255.
461 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
462 * (2 channel) streams.
463 * This must be no larger than the total
464 * number of streams.
465 * Additionally, The total number of
466 * coded channels (<code>streams +
467 * coupled_streams</code>) must be no
468 * more than 255.
469 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
470 * coded channels to output channels, as described in
471 * @ref opus_multistream.
472 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
473 * code (see @ref opus_errorcodes) on
474 * failure.
475 */
476OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
477 opus_int32 Fs,
478 int channels,
479 int streams,
480 int coupled_streams,
481 const unsigned char *mapping,
482 int *error
483) OPUS_ARG_NONNULL(5);
484
485/** Intialize a previously allocated decoder state object.
486 * The memory pointed to by \a st must be at least the size returned by
487 * opus_multistream_encoder_get_size().
488 * This is intended for applications which use their own allocator instead of
489 * malloc.
490 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
491 * @see opus_multistream_decoder_create
492 * @see opus_multistream_deocder_get_size
493 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
494 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
495 * This must be one of 8000, 12000, 16000,
496 * 24000, or 48000.
497 * @param channels <tt>int</tt>: Number of channels to output.
498 * This must be at most 255.
499 * It may be different from the number of coded
500 * channels (<code>streams +
501 * coupled_streams</code>).
502 * @param streams <tt>int</tt>: The total number of streams coded in the
503 * input.
504 * This must be no more than 255.
505 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
506 * (2 channel) streams.
507 * This must be no larger than the total
508 * number of streams.
509 * Additionally, The total number of
510 * coded channels (<code>streams +
511 * coupled_streams</code>) must be no
512 * more than 255.
513 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
514 * coded channels to output channels, as described in
515 * @ref opus_multistream.
516 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
517 * on failure.
518 */
519OPUS_EXPORT int opus_multistream_decoder_init(
520 OpusMSDecoder *st,
521 opus_int32 Fs,
522 int channels,
523 int streams,
524 int coupled_streams,
525 const unsigned char *mapping
526) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
527
528/** Decode a multistream Opus packet.
529 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
530 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
531 * Use a <code>NULL</code>
532 * pointer to indicate packet
533 * loss.
534 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
535 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
536 * samples.
537 * This must contain room for
538 * <code>frame_size*channels</code>
539 * samples.
540 * @param frame_size <tt>int</tt>: The number of samples per channel of
541 * available space in \a pcm.
542 * If this is less than the maximum packet duration
543 * (120 ms; 5760 for 48kHz), this function will not be capable
544 * of decoding some packets. In the case of PLC (data==NULL)
545 * or FEC (decode_fec=1), then frame_size needs to be exactly
546 * the duration of audio that is missing, otherwise the
547 * decoder will not be in the optimal state to decode the
548 * next incoming packet. For the PLC and FEC cases, frame_size
549 * <b>must</b> be a multiple of 2.5 ms.
550 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
551 * forward error correction data be decoded.
552 * If no such data is available, the frame is
553 * decoded as if it were lost.
554 * @returns Number of samples decoded on success or a negative error code
555 * (see @ref opus_errorcodes) on failure.
556 */
557OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
558 OpusMSDecoder *st,
559 const unsigned char *data,
560 opus_int32 len,
561 opus_int16 *pcm,
562 int frame_size,
563 int decode_fec
564) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
565
566/** Decode a multistream Opus packet with floating point output.
567 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
568 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
569 * Use a <code>NULL</code>
570 * pointer to indicate packet
571 * loss.
572 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
573 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
574 * samples.
575 * This must contain room for
576 * <code>frame_size*channels</code>
577 * samples.
578 * @param frame_size <tt>int</tt>: The number of samples per channel of
579 * available space in \a pcm.
580 * If this is less than the maximum packet duration
581 * (120 ms; 5760 for 48kHz), this function will not be capable
582 * of decoding some packets. In the case of PLC (data==NULL)
583 * or FEC (decode_fec=1), then frame_size needs to be exactly
584 * the duration of audio that is missing, otherwise the
585 * decoder will not be in the optimal state to decode the
586 * next incoming packet. For the PLC and FEC cases, frame_size
587 * <b>must</b> be a multiple of 2.5 ms.
588 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
589 * forward error correction data be decoded.
590 * If no such data is available, the frame is
591 * decoded as if it were lost.
592 * @returns Number of samples decoded on success or a negative error code
593 * (see @ref opus_errorcodes) on failure.
594 */
595OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
596 OpusMSDecoder *st,
597 const unsigned char *data,
598 opus_int32 len,
599 float *pcm,
600 int frame_size,
601 int decode_fec
602) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
603
604/** Perform a CTL function on a multistream Opus decoder.
605 *
606 * Generally the request and subsequent arguments are generated by a
607 * convenience macro.
608 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
609 * @param request This and all remaining parameters should be replaced by one
610 * of the convenience macros in @ref opus_genericctls,
611 * @ref opus_decoderctls, or @ref opus_multistream_ctls.
612 * @see opus_genericctls
613 * @see opus_decoderctls
614 * @see opus_multistream_ctls
615 */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000616OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
617
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000618/** Frees an <code>OpusMSDecoder</code> allocated by
619 * opus_multistream_decoder_create().
620 * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
621 */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000622OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
623
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000624/**@}*/
625
626/**@}*/
627
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000628#ifdef __cplusplus
629}
630#endif
631
632#endif /* OPUS_MULTISTREAM_H */