annotate osx/include/opus/opus_multistream.h @ 69:7aeed7906520

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