blob: be1b44df61d0097f2a28a158c95a6d9dcca6ba8c [file] [log] [blame]
Jean-Marc Valind4e93402011-08-27 00:52:26 -04001/* 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
Jean-Marc Valincb05e7c2012-04-20 16:40:24 -040018 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Jean-Marc Valind4e93402011-08-27 00:52:26 -040020 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
Ralph Giles1b951962011-09-07 10:40:25 -070028/**
29 * @file opus_multistream.h
30 * @brief Opus reference implementation multistream API
31 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -040032
33#ifndef OPUS_MULTISTREAM_H
34#define OPUS_MULTISTREAM_H
35
36#include "opus.h"
37
Ralph Giles64c2dd72012-05-23 16:33:14 -070038#ifdef __cplusplus
39extern "C" {
40#endif
41
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070042/** @cond OPUS_INTERNAL_DOC */
Jean-Marc Valind4e93402011-08-27 00:52:26 -040043
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070044/** Macros to trigger compilation errors when the wrong types are provided to a
45 * CTL. */
46/**@{*/
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040047#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
48#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070049/**@}*/
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040050
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070051/** 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/**@{*/
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040055#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
56#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070057/**@}*/
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040058
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070059/** @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 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 */
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040086#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070087
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 */
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040099#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
100
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700101/**@}*/
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400102
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700103/** @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 negotation.
112 *
113 * The format for multistream Opus packets is defined in the
114 * <a href="http://tools.ietf.org/html/draft-terriberry-oggopus-01">Ogg
115 * encapsulation specification</a>.
116 * Normal Opus packets are just a degenerate case of multistream Opus packets,
117 * and can be encoded or decoded with the multistream API by setting
118 * <code>streams</code> to <code>1</code> when initializing the encoder or
119 * decoder.
120 *
121 * Multistream Opus streams can contain up to 255 elementary Opus streams.
122 * These may be either "uncoupled" or "coupled", indicating that the decoder
123 * is configured to decode them to either 1 or 2 channels, respectively.
124 * The streams are ordered so that all coupled streams appear at the
125 * beginning.
126 *
127 * A <code>mapping</code> table defines which decoded channel should be used
128 * for each output channel. The output channels specified by the encoder
129 * should use the
130 * <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
131 * channel ordering</a>. A decoder may wish to apply an additional permutation
132 * to the mapping the encoder used to achieve a different output channel
133 * order.
134 *
135 * Each multistream packet contains an Opus packet for each stream, and all of
136 * the Opus packets in a single multistream packet must have the same
137 * duration. Therefore the duration of a multistream packet can be extracted
138 * from the TOC sequence of the first stream, which is located at the
139 * beginning of the packet, just like an elementary Opus stream:
140 *
141 * @code
142 * int nb_samples;
143 * int nb_frames;
144 * nb_frames = opus_packet_get_nb_frames(data, len);
145 * if (nb_frames < 1)
146 * return nb_frames;
147 * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;
148 * @endcode
149 *
150 * The general encoding and decoding process proceeds exactly the same as in
151 * the normal @ref opus_encoder and @ref opus_decoder APIs.
152 * See their documentation for an overview of how to use the corresponding
153 * multistream functions.
154 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400155
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700156/** Opus multistream encoder state.
157 * This contains the complete state of a multistream Opus encoder.
158 * It is position independent and can be freely copied.
159 * @see opus_multistream_encoder_create
160 * @see opus_multistream_encoder_init
161 */
162typedef struct OpusMSEncoder OpusMSEncoder;
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400163
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700164/** Opus multistream decoder state.
165 * This contains the complete state of a multistream Opus decoder.
166 * It is position independent and can be freely copied.
167 * @see opus_multistream_decoder_create
168 * @see opus_multistream_decoder_init
169 */
170typedef struct OpusMSDecoder OpusMSDecoder;
171
172/**\name Multistream encoder functions */
173/**@{*/
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400174
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400175/** Gets the size of an OpusMSEncoder structure.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700176 * @param streams <tt>int</tt>: The total number of streams to encode from the
177 * input.
178 * This must be no more than 255.
179 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
180 * to encode.
181 * This must be no larger than the total
182 * number of streams.
183 * Additionally, The total number of
184 * encoded channels (<code>streams +
185 * coupled_streams</code>) must be no
186 * more than 255.
187 * @returns The size in bytes on success, or a negative error code
188 * (see @ref opus_errorcodes) on error.
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400189 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400190OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700191 int streams,
192 int coupled_streams
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400193);
194
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700195/** Allocates and initializes a multistream encoder state.
196 * Call opus_multistream_encoder_destroy() to release
197 * this object when finished.
198 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
199 * This must be one of 8000, 12000, 16000,
200 * 24000, or 48000.
201 * @param channels <tt>int</tt>: Number of channels in the input signal.
202 * This must be at most 255.
203 * It may be different from the number of
204 * channels (<code>streams +
205 * coupled_streams</code>).
206 * @param streams <tt>int</tt>: The total number of streams to encode from the
207 * input.
208 * This must be no more than 255.
209 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
210 * to encode.
211 * This must be no larger than the total
212 * number of streams.
213 * Additionally, The total number of
214 * encoded channels (<code>streams +
215 * coupled_streams</code>) must be no
216 * more than 255.
217 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
218 * encoded channels to input channels.
219 * Let <code>i = mapping[j]</code> be the index for input
220 * channel <code>j</code>.
221 * If <code>i < 2*coupled_streams</code>, then input
222 * channel <code>j</code> is encoded as the left channel of
223 * stream <code>(i/2)</code> if <code>i</code> is even, and
224 * as the right channel of stream <code>(i/2)</code> if
225 * <code>i</code> is odd.
226 * Otherwise, input channel <code>j</code> is encoded as
227 * mono in stream <code>(i - coupled_streams)</code>,
228 * unless it has the special value 255, in which case it is
229 * omitted from the encoding entirely (the decoder will
230 * reproduce it as silence).
231 * Each value <code>i</code> must either be the special
232 * value 255 or be less than
233 * <code>streams + coupled_streams</code>.
234 * @param application <tt>int</tt>: The target encoder application.
235 * This must be one of the following:
236 * <dl>
237 * <dt>#OPUS_APPLICATION_VOIP</dt>
238 * <dd>Process signal for improved speech intelligibility.</dd>
239 * <dt>#OPUS_APPLICATION_AUDIO</dt>
240 * <dd>Favor faithfulness to the original input.</dd>
241 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
242 * <dd>Configure the minimum possible coding delay by disabling certain modes
243 * of operation.</dd>
244 * </dl>
245 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
246 * code (see @ref opus_errorcodes) on
247 * failure.
248 */
249OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
250 opus_int32 Fs,
251 int channels,
252 int streams,
253 int coupled_streams,
254 const unsigned char *mapping,
255 int application,
256 int *error
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400257) OPUS_ARG_NONNULL(5);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400258
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700259/** Initialize a previously allocated multistream encoder state.
260 * The memory pointed to by \a st must be the size returned by
261 * opus_multistream_encoder_get_size().
262 * This is intended for applications which use their own allocator instead of
263 * malloc.
264 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
265 * @see opus_multistream_encoder_create
266 * @see opus_multistream_encoder_get_size
267 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
268 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
269 * This must be one of 8000, 12000, 16000,
270 * 24000, or 48000.
271 * @param channels <tt>int</tt>: Number of channels in the input signal.
272 * This must be at most 255.
273 * It may be different from the number of
274 * coded channels (<code>streams +
275 * coupled_streams</code>).
276 * @param streams <tt>int</tt>: The total number of streams to encode from the
277 * input.
278 * This must be no more than 255.
279 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
280 * to encode.
281 * This must be no larger than the total
282 * number of streams.
283 * Additionally, The total number of
284 * encoded channels (<code>streams +
285 * coupled_streams</code>) must be no
286 * more than 255.
287 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
288 * encoded channels to input channels.
289 * See opus_multistream_encoder_create() for details.
290 * @param application <tt>int</tt>: The target encoder application.
291 * This must be one of the following:
292 * <dl>
293 * <dt>#OPUS_APPLICATION_VOIP</dt>
294 * <dd>Process signal for improved speech intelligibility.</dd>
295 * <dt>#OPUS_APPLICATION_AUDIO</dt>
296 * <dd>Favor faithfulness to the original input.</dd>
297 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
298 * <dd>Configure the minimum possible coding delay by disabling certain modes
299 * of operation.</dd>
300 * </dl>
301 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
302 * on failure.
303 */
304OPUS_EXPORT int opus_multistream_encoder_init(
305 OpusMSEncoder *st,
306 opus_int32 Fs,
307 int channels,
308 int streams,
309 int coupled_streams,
310 const unsigned char *mapping,
311 int application
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400312) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400313
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700314/** Encodes a multistream Opus frame.
315 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
316 * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
317 * samples.
318 * This must contain
319 * <code>frame_size*channels</code>
320 * samples.
321 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
322 * signal.
323 * This must be an Opus frame size for the
324 * encoder's sampling rate.
325 * For example, at 48 kHz the permitted values
326 * are 120, 240, 480, 960, 1920, and 2880.
327 * Passing in a duration of less than 10 ms
328 * (480 samples at 48 kHz) will prevent the
329 * encoder from using the LPC or hybrid modes.
330 * @param[out] data <tt>unsigned char*</tt>: Output payload.
331 * This must contain storage for at
332 * least \a max_data_bytes.
333 * @param max_data_bytes <tt>opus_int32</tt>: Size of the allocated memory for
334 * the output payload.
335 * This should not be used by
336 * itself to control the bitrate.
337 * @returns The length of the encoded packet (in bytes) on success or a
338 * negative error code (see @ref opus_errorcodes) on failure.
339 */
340OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
341 OpusMSEncoder *st,
342 const opus_int16 *pcm,
343 int frame_size,
344 unsigned char *data,
345 opus_int32 max_data_bytes
346) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400347
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700348/** Encodes a multistream Opus frame from floating point input.
349 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
350 * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
351 * samples with a normal range of
352 * +/-1.0.
353 * Samples with a range beyond +/-1.0
354 * are supported but will be clipped by
355 * decoders using the integer API and
356 * should only be used if it is known
357 * that the far end supports extended
358 * dynamic range.
359 * This must contain
360 * <code>frame_size*channels</code>
361 * samples.
362 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
363 * signal.
364 * This must be an Opus frame size for the
365 * encoder's sampling rate.
366 * For example, at 48 kHz the permitted values
367 * are 120, 240, 480, 960, 1920, and 2880.
368 * Passing in a duration of less than 10 ms
369 * (480 samples at 48 kHz) will prevent the
370 * encoder from using the LPC or hybrid modes.
371 * @param[out] data <tt>unsigned char*</tt>: Output payload.
372 * This must contain storage for at
373 * least \a max_data_bytes.
374 * @param max_data_bytes <tt>opus_int32</tt>: Size of the allocated memory for
375 * the output payload.
376 * This should not be used by
377 * itself to control the bitrate.
378 * @returns The length of the encoded packet (in bytes) on success or a
379 * negative error code (see @ref opus_errorcodes) on failure.
380 */
381OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
382 OpusMSEncoder *st,
383 const float *pcm,
384 int frame_size,
385 unsigned char *data,
386 opus_int32 max_data_bytes
387) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400388
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700389/** Frees an <code>OpusMSEncoder</code> allocated by
390 * opus_multistream_encoder_create().
391 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
392 */
393OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
394
395/** Perform a CTL function on a multistream Opus encoder.
396 *
397 * Generally the request and subsequent arguments are generated by a
398 * convenience macro.
399 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
400 * @param request This and all remaining parameters should be replaced by one
401 * of the convenience macros in @ref opus_genericctls,
402 * @ref opus_encoderctls, or @ref opus_multistream_ctls.
403 * @see opus_genericctls
404 * @see opus_encoderctls
405 * @see opus_multistream_ctls
406 */
407OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
408
409/**@}*/
410
411/**\name Multistream decoder functions */
412/**@{*/
413
414/** Gets the size of an <code>OpusMSDecoder</code> structure.
415 * @param streams <tt>int</tt>: The total number of streams coded in the
416 * input.
417 * This must be no more than 255.
418 * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
419 * (2 channel) streams.
420 * This must be no larger than the total
421 * number of streams.
422 * Additionally, The total number of
423 * coded channels (<code>streams +
424 * coupled_streams</code>) must be no
425 * more than 255.
426 * @returns The size in bytes on success, or a negative error code
427 * (see @ref opus_errorcodes) on error.
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400428 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400429OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700430 int streams,
431 int coupled_streams
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400432);
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700433
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700434/** Allocates and initializes a multistream decoder state.
435 * Call opus_multistream_decoder_destroy() to release
436 * this object when finished.
437 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
438 * This must be one of 8000, 12000, 16000,
439 * 24000, or 48000.
440 * @param channels <tt>int</tt>: Number of channels to decode.
441 * This must be at most 255.
442 * It may be different from the number of coded
443 * channels (<code>streams +
444 * coupled_streams</code>).
445 * @param streams <tt>int</tt>: The total number of streams coded in the
446 * input.
447 * This must be no more than 255.
448 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
449 * (2 channel) streams.
450 * This must be no larger than the total
451 * number of streams.
452 * Additionally, The total number of
453 * coded channels (<code>streams +
454 * coupled_streams</code>) must be no
455 * more than 255.
456 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
457 * coded channels to output channels.
458 * Let <code>i = mapping[j]</code> be the index for output
459 * channel <code>j</code>.
460 * If <code>i < 2*coupled_streams</code>, then the output
461 * for channel <code>j</code> is taken from the left
462 * channel of stream <code>(i/2)</code> if <code>i</code>
463 * <code>i</code> is even, and from the right channel of
464 * stream <code>(i/2)</code> if <code>i</code> is odd.
465 * Otherwise, the output for channel <code>j</code> is
466 * taken from stream <code>(i - coupled_streams)</code>
467 * decoded as mono, unless it has the special value 255, in
468 * which case silence is used instead.
469 * Each value <code>i</code> must either be the special
470 * value 255 or be less than
471 * <code>streams + coupled_streams</code>.
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 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 decode.
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.
515 * See opus_multistream_decoder_create() for details.
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 frame size
543 * (120 ms), this function will not be capable
544 * of decoding some packets.
545 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
546 * forward error correction data be decoded.
547 * If no such data is available, the frame is
548 * decoded as if it were lost.
549 * @returns Number of samples decoded on success or a negative error code
550 * (see @ref opus_errorcodes) on failure.
551 */
552OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
553 OpusMSDecoder *st,
554 const unsigned char *data,
555 opus_int32 len,
556 opus_int16 *pcm,
557 int frame_size,
558 int decode_fec
559) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
560
561/** Decode a multistream Opus packet with floating point output.
562 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
563 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
564 * Use a <code>NULL</code>
565 * pointer to indicate packet
566 * loss.
567 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
568 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
569 * samples.
570 * This must contain room for
571 * <code>frame_size*channels</code>
572 * samples.
573 * @param frame_size <tt>int</tt>: The number of samples per channel of
574 * available space in \a pcm.
575 * If this is less than the maximum frame size
576 * (120 ms), this function will not be capable
577 * of decoding some packets.
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 */
585OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
586 OpusMSDecoder *st,
587 const unsigned char *data,
588 opus_int32 len,
589 float *pcm,
590 int frame_size,
591 int decode_fec
592) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
593
594/** Perform a CTL function on a multistream Opus decoder.
595 *
596 * Generally the request and subsequent arguments are generated by a
597 * convenience macro.
598 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
599 * @param request This and all remaining parameters should be replaced by one
600 * of the convenience macros in @ref opus_genericctls,
601 * @ref opus_decoderctls, or @ref opus_multistream_ctls.
602 * @see opus_genericctls
603 * @see opus_decoderctls
604 * @see opus_multistream_ctls
605 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400606OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400607
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700608/** Frees an <code>OpusMSDecoder</code> allocated by
609 * opus_multistream_decoder_create().
610 * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
611 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400612OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
613
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700614/**@}*/
615
616/**@}*/
617
Ralph Giles64c2dd72012-05-23 16:33:14 -0700618#ifdef __cplusplus
619}
620#endif
621
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400622#endif /* OPUS_MULTISTREAM_H */