annotate osx/include/opus/opus_multistream.h @ 169:223a55898ab9 tip default

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