blob: f476efa6a80c00c25dff458dd46632e80509a80e [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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -040071 * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -070072 */
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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400114 * <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>.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700117 * 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 *
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400128 * 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
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700142 * 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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400146 * order (e.g. for outputing in WAV order).
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700147 *
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 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400168
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700169/** 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;
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400176
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700177/** 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/**@{*/
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400187
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400188/** Gets the size of an OpusMSEncoder structure.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700189 * @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.
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400202 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400203OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700204 int streams,
205 int coupled_streams
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400206);
207
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700208/** 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.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400216 * It may be greater than the number of
217 * coded channels (<code>streams +
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700218 * coupled_streams</code>).
219 * @param streams <tt>int</tt>: The total number of streams to encode from the
220 * input.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400221 * This must be no more than the number of channels.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700222 * @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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400229 * more than the number of input channels.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700230 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400231 * 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.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700236 * @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
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400259) OPUS_ARG_NONNULL(5);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400260
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700261/** Initialize a previously allocated multistream encoder state.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400262 * The memory pointed to by \a st must be at least the size returned by
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700263 * 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.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400275 * It may be greater than the number of
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700276 * 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.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400280 * This must be no more than the number of channels.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700281 * @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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400288 * more than the number of input channels.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700289 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400290 * 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.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700295 * @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
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400317) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400318
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700319/** 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
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400322 * samples.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700323 * 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 max_data_bytes <tt>opus_int32</tt>: Size of the allocated memory for
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400339 * the output payload. This may be
340 * used to impose an upper limit on
341 * the variable bitrate, but should
342 * not be used as the only bitrate
343 * control.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700344 * @returns The length of the encoded packet (in bytes) on success or a
345 * negative error code (see @ref opus_errorcodes) on failure.
346 */
347OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
348 OpusMSEncoder *st,
349 const opus_int16 *pcm,
350 int frame_size,
351 unsigned char *data,
352 opus_int32 max_data_bytes
353) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400354
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700355/** Encodes a multistream Opus frame from floating point input.
356 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
357 * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
358 * samples with a normal range of
359 * +/-1.0.
360 * Samples with a range beyond +/-1.0
361 * are supported but will be clipped by
362 * decoders using the integer API and
363 * should only be used if it is known
364 * that the far end supports extended
365 * dynamic range.
366 * This must contain
367 * <code>frame_size*channels</code>
368 * samples.
369 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
370 * signal.
371 * This must be an Opus frame size for the
372 * encoder's sampling rate.
373 * For example, at 48 kHz the permitted values
374 * are 120, 240, 480, 960, 1920, and 2880.
375 * Passing in a duration of less than 10 ms
376 * (480 samples at 48 kHz) will prevent the
377 * encoder from using the LPC or hybrid modes.
378 * @param[out] data <tt>unsigned char*</tt>: Output payload.
379 * This must contain storage for at
380 * least \a max_data_bytes.
381 * @param max_data_bytes <tt>opus_int32</tt>: Size of the allocated memory for
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400382 * the output payload. This may be
383 * used to impose an upper limit on
384 * the variable bitrate, but should
385 * not be used as the only bitrate
386 * control.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700387 * @returns The length of the encoded packet (in bytes) on success or a
388 * negative error code (see @ref opus_errorcodes) on failure.
389 */
390OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
391 OpusMSEncoder *st,
392 const float *pcm,
393 int frame_size,
394 unsigned char *data,
395 opus_int32 max_data_bytes
396) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400397
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700398/** Frees an <code>OpusMSEncoder</code> allocated by
399 * opus_multistream_encoder_create().
400 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
401 */
402OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
403
404/** Perform a CTL function on a multistream Opus encoder.
405 *
406 * Generally the request and subsequent arguments are generated by a
407 * convenience macro.
408 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
409 * @param request This and all remaining parameters should be replaced by one
410 * of the convenience macros in @ref opus_genericctls,
411 * @ref opus_encoderctls, or @ref opus_multistream_ctls.
412 * @see opus_genericctls
413 * @see opus_encoderctls
414 * @see opus_multistream_ctls
415 */
416OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
417
418/**@}*/
419
420/**\name Multistream decoder functions */
421/**@{*/
422
423/** Gets the size of an <code>OpusMSDecoder</code> structure.
424 * @param streams <tt>int</tt>: The total number of streams coded in the
425 * input.
426 * This must be no more than 255.
427 * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
428 * (2 channel) streams.
429 * This must be no larger than the total
430 * number of streams.
431 * Additionally, The total number of
432 * coded channels (<code>streams +
433 * coupled_streams</code>) must be no
434 * more than 255.
435 * @returns The size in bytes on success, or a negative error code
436 * (see @ref opus_errorcodes) on error.
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400437 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400438OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700439 int streams,
440 int coupled_streams
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400441);
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700442
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700443/** Allocates and initializes a multistream decoder state.
444 * Call opus_multistream_decoder_destroy() to release
445 * this object when finished.
446 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
447 * This must be one of 8000, 12000, 16000,
448 * 24000, or 48000.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400449 * @param channels <tt>int</tt>: Number of channels to output.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700450 * This must be at most 255.
451 * It may be different from the number of coded
452 * channels (<code>streams +
453 * coupled_streams</code>).
454 * @param streams <tt>int</tt>: The total number of streams coded in the
455 * input.
456 * This must be no more than 255.
457 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
458 * (2 channel) streams.
459 * This must be no larger than the total
460 * number of streams.
461 * Additionally, The total number of
462 * coded channels (<code>streams +
463 * coupled_streams</code>) must be no
464 * more than 255.
465 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400466 * coded channels to output channels, as described in
467 * @ref opus_multistream.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700468 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
469 * code (see @ref opus_errorcodes) on
470 * failure.
471 */
472OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
473 opus_int32 Fs,
474 int channels,
475 int streams,
476 int coupled_streams,
477 const unsigned char *mapping,
478 int *error
479) OPUS_ARG_NONNULL(5);
480
481/** Intialize a previously allocated decoder state object.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400482 * The memory pointed to by \a st must be at least the size returned by
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700483 * opus_multistream_encoder_get_size().
484 * This is intended for applications which use their own allocator instead of
485 * malloc.
486 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
487 * @see opus_multistream_decoder_create
488 * @see opus_multistream_deocder_get_size
489 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
490 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
491 * This must be one of 8000, 12000, 16000,
492 * 24000, or 48000.
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400493 * @param channels <tt>int</tt>: Number of channels to output.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700494 * This must be at most 255.
495 * It may be different from the number of coded
496 * channels (<code>streams +
497 * coupled_streams</code>).
498 * @param streams <tt>int</tt>: The total number of streams coded in the
499 * input.
500 * This must be no more than 255.
501 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
502 * (2 channel) streams.
503 * This must be no larger than the total
504 * number of streams.
505 * Additionally, The total number of
506 * coded channels (<code>streams +
507 * coupled_streams</code>) must be no
508 * more than 255.
509 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
Jean-Marc Valin1d13ff62012-09-10 21:47:09 -0400510 * coded channels to output channels, as described in
511 * @ref opus_multistream.
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700512 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
513 * on failure.
514 */
515OPUS_EXPORT int opus_multistream_decoder_init(
516 OpusMSDecoder *st,
517 opus_int32 Fs,
518 int channels,
519 int streams,
520 int coupled_streams,
521 const unsigned char *mapping
522) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
523
524/** Decode a multistream Opus packet.
525 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
526 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
527 * Use a <code>NULL</code>
528 * pointer to indicate packet
529 * loss.
530 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
531 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
532 * samples.
533 * This must contain room for
534 * <code>frame_size*channels</code>
535 * samples.
536 * @param frame_size <tt>int</tt>: The number of samples per channel of
537 * available space in \a pcm.
538 * If this is less than the maximum frame size
539 * (120 ms), this function will not be capable
540 * of decoding some packets.
541 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
542 * forward error correction data be decoded.
543 * If no such data is available, the frame is
544 * decoded as if it were lost.
545 * @returns Number of samples decoded on success or a negative error code
546 * (see @ref opus_errorcodes) on failure.
547 */
548OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
549 OpusMSDecoder *st,
550 const unsigned char *data,
551 opus_int32 len,
552 opus_int16 *pcm,
553 int frame_size,
554 int decode_fec
555) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
556
557/** Decode a multistream Opus packet with floating point output.
558 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
559 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
560 * Use a <code>NULL</code>
561 * pointer to indicate packet
562 * loss.
563 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
564 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
565 * samples.
566 * This must contain room for
567 * <code>frame_size*channels</code>
568 * samples.
569 * @param frame_size <tt>int</tt>: The number of samples per channel of
570 * available space in \a pcm.
571 * If this is less than the maximum frame size
572 * (120 ms), this function will not be capable
573 * of decoding some packets.
574 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
575 * forward error correction data be decoded.
576 * If no such data is available, the frame is
577 * decoded as if it were lost.
578 * @returns Number of samples decoded on success or a negative error code
579 * (see @ref opus_errorcodes) on failure.
580 */
581OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
582 OpusMSDecoder *st,
583 const unsigned char *data,
584 opus_int32 len,
585 float *pcm,
586 int frame_size,
587 int decode_fec
588) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
589
590/** Perform a CTL function on a multistream Opus decoder.
591 *
592 * Generally the request and subsequent arguments are generated by a
593 * convenience macro.
594 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
595 * @param request This and all remaining parameters should be replaced by one
596 * of the convenience macros in @ref opus_genericctls,
597 * @ref opus_decoderctls, or @ref opus_multistream_ctls.
598 * @see opus_genericctls
599 * @see opus_decoderctls
600 * @see opus_multistream_ctls
601 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400602OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400603
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700604/** Frees an <code>OpusMSDecoder</code> allocated by
605 * opus_multistream_decoder_create().
606 * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
607 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400608OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
609
Timothy B. Terriberry77ebbdf2012-09-09 07:22:11 -0700610/**@}*/
611
612/**@}*/
613
Ralph Giles64c2dd72012-05-23 16:33:14 -0700614#ifdef __cplusplus
615}
616#endif
617
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400618#endif /* OPUS_MULTISTREAM_H */