OLD | NEW |
1 /* Copyright (c) 2011 Xiph.Org Foundation | 1 /* Copyright (c) 2011 Xiph.Org Foundation |
2 Written by Jean-Marc Valin */ | 2 Written by Jean-Marc Valin */ |
3 /* | 3 /* |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #ifndef OPUS_MULTISTREAM_H | 33 #ifndef OPUS_MULTISTREAM_H |
34 #define OPUS_MULTISTREAM_H | 34 #define OPUS_MULTISTREAM_H |
35 | 35 |
36 #include "opus.h" | 36 #include "opus.h" |
37 | 37 |
38 #ifdef __cplusplus | 38 #ifdef __cplusplus |
39 extern "C" { | 39 extern "C" { |
40 #endif | 40 #endif |
41 | 41 |
42 typedef struct OpusMSEncoder OpusMSEncoder; | 42 /** @cond OPUS_INTERNAL_DOC */ |
43 typedef struct OpusMSDecoder OpusMSDecoder; | 43 |
44 | 44 /** Macros to trigger compilation errors when the wrong types are provided to a |
| 45 * CTL. */ |
| 46 /**@{*/ |
45 #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) | 47 #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) |
46 #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) | 48 #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) |
47 | 49 /**@}*/ |
| 50 |
| 51 /** 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 /**@{*/ |
48 #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 | 55 #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 |
49 #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 | 56 #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 |
50 | 57 /**@}*/ |
| 58 |
| 59 /** @endcond */ |
| 60 |
| 61 /** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTL
s |
| 62 * |
| 63 * These are convenience macros that are specific to the |
| 64 * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() |
| 65 * interface. |
| 66 * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and |
| 67 * @ref opus_decoderctls may be applied to a multistream encoder or decoder as |
| 68 * well. |
| 69 * In addition, you may retrieve the encoder or decoder state for an specific |
| 70 * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or |
| 71 * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. |
| 72 */ |
| 73 /**@{*/ |
| 74 |
| 75 /** Gets the encoder state for an individual stream of a multistream encoder. |
| 76 * @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder you |
| 77 * wish to retrieve. |
| 78 * This must be non-negative and less than |
| 79 * the <code>streams</code> parameter used |
| 80 * to initialize the encoder. |
| 81 * @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given |
| 82 * encoder state. |
| 83 * @retval OPUS_BAD_ARG The index of the requested stream was out of range. |
| 84 * @hideinitializer |
| 85 */ |
51 #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STA
TE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) | 86 #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STA
TE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) |
| 87 |
| 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 */ |
52 #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STA
TE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) | 99 #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STA
TE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) |
53 | 100 |
54 /** Allocate and initialize a multistream encoder state object. | 101 /**@}*/ |
55 * Call opus_multistream_encoder_destroy() to release | 102 |
56 * this object when finished. */ | 103 /** @defgroup opus_multistream Opus Multistream API |
| 104 * @{ |
| 105 * |
| 106 * The multistream API allows individual Opus streams to be combined into a |
| 107 * single packet, enabling support for up to 255 channels. Unlike an |
| 108 * elementary Opus stream, the encoder and decoder must negotiate the channel |
| 109 * configuration before the decoder can successfully interpret the data in the |
| 110 * packets produced by the encoder. Some basic information, such as packet |
| 111 * duration, can be computed without any special negotiation. |
| 112 * |
| 113 * The format for multistream Opus packets is defined in the |
| 114 * <a href="http://tools.ietf.org/html/draft-terriberry-oggopus">Ogg |
| 115 * encapsulation specification</a> and is based on the self-delimited Opus |
| 116 * framing described in Appendix B of <a href="http://tools.ietf.org/html/rfc67
16">RFC 6716</a>. |
| 117 * Normal Opus packets are just a degenerate case of multistream Opus packets, |
| 118 * and can be encoded or decoded with the multistream API by setting |
| 119 * <code>streams</code> to <code>1</code> when initializing the encoder or |
| 120 * decoder. |
| 121 * |
| 122 * Multistream Opus streams can contain up to 255 elementary Opus streams. |
| 123 * These may be either "uncoupled" or "coupled", indicating that the decoder |
| 124 * is configured to decode them to either 1 or 2 channels, respectively. |
| 125 * The streams are ordered so that all coupled streams appear at the |
| 126 * beginning. |
| 127 * |
| 128 * A <code>mapping</code> table defines which decoded channel <code>i</code> |
| 129 * should be used for each input/output (I/O) channel <code>j</code>. This tabl
e 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</co
de>. |
| 140 * |
| 141 * The output channels specified by the encoder |
| 142 * should use the |
| 143 * <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vo
rbis |
| 144 * channel ordering</a>. A decoder may wish to apply an additional permutation |
| 145 * to the mapping the encoder used to achieve a different output channel |
| 146 * order (e.g. for outputing in WAV order). |
| 147 * |
| 148 * Each multistream packet contains an Opus packet for each stream, and all of |
| 149 * the Opus packets in a single multistream packet must have the same |
| 150 * duration. Therefore the duration of a multistream packet can be extracted |
| 151 * from the TOC sequence of the first stream, which is located at the |
| 152 * beginning of the packet, just like an elementary Opus stream: |
| 153 * |
| 154 * @code |
| 155 * int nb_samples; |
| 156 * int nb_frames; |
| 157 * nb_frames = opus_packet_get_nb_frames(data, len); |
| 158 * if (nb_frames < 1) |
| 159 * return nb_frames; |
| 160 * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; |
| 161 * @endcode |
| 162 * |
| 163 * The general encoding and decoding process proceeds exactly the same as in |
| 164 * the normal @ref opus_encoder and @ref opus_decoder APIs. |
| 165 * See their documentation for an overview of how to use the corresponding |
| 166 * multistream functions. |
| 167 */ |
| 168 |
| 169 /** 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 */ |
| 175 typedef struct OpusMSEncoder OpusMSEncoder; |
| 176 |
| 177 /** 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 */ |
| 183 typedef struct OpusMSDecoder OpusMSDecoder; |
| 184 |
| 185 /**\name Multistream encoder functions */ |
| 186 /**@{*/ |
| 187 |
| 188 /** Gets the size of an OpusMSEncoder structure. |
| 189 * @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. |
| 202 */ |
| 203 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size
( |
| 204 int streams, |
| 205 int coupled_streams |
| 206 ); |
| 207 |
| 208 /** Allocates and initializes a multistream encoder state. |
| 209 * Call opus_multistream_encoder_destroy() to release |
| 210 * this object when finished. |
| 211 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz). |
| 212 * This must be one of 8000, 12000, 16000, |
| 213 * 24000, or 48000. |
| 214 * @param channels <tt>int</tt>: Number of channels in the input signal. |
| 215 * This must be at most 255. |
| 216 * It may be greater than the number of |
| 217 * coded channels (<code>streams + |
| 218 * coupled_streams</code>). |
| 219 * @param streams <tt>int</tt>: The total number of streams to encode from the |
| 220 * input. |
| 221 * This must be no more than the number of channel
s. |
| 222 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams |
| 223 * to encode. |
| 224 * This must be no larger than the total |
| 225 * number of streams. |
| 226 * Additionally, The total number of |
| 227 * encoded channels (<code>streams + |
| 228 * coupled_streams</code>) must be no |
| 229 * more than the number of input channels. |
| 230 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from |
| 231 * encoded channels to input channels, as described in |
| 232 * @ref opus_multistream. As an extra constraint, the |
| 233 * multistream encoder does not allow encoding coupled |
| 234 * streams for which one channel is unused since this |
| 235 * is never a good idea. |
| 236 * @param application <tt>int</tt>: The target encoder application. |
| 237 * This must be one of the following: |
| 238 * <dl> |
| 239 * <dt>#OPUS_APPLICATION_VOIP</dt> |
| 240 * <dd>Process signal for improved speech intelligibility.</dd> |
| 241 * <dt>#OPUS_APPLICATION_AUDIO</dt> |
| 242 * <dd>Favor faithfulness to the original input.</dd> |
| 243 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> |
| 244 * <dd>Configure the minimum possible coding delay by disabling certain modes |
| 245 * of operation.</dd> |
| 246 * </dl> |
| 247 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error |
| 248 * code (see @ref opus_errorcodes) on |
| 249 * failure. |
| 250 */ |
57 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_crea
te( | 251 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_crea
te( |
58 opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ | 252 opus_int32 Fs, |
59 int channels, /**< Number of channels in the input signal */ | 253 int channels, |
60 int streams, /**< Total number of streams to encode from the
input */ | 254 int streams, |
61 int coupled_streams, /**< Number of coupled (stereo) streams to encod
e */ | 255 int coupled_streams, |
62 const unsigned char *mapping, /**< Encoded mapping between channels and st
reams */ | 256 const unsigned char *mapping, |
63 int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APP
LICATION_AUDIO) */ | 257 int application, |
64 int *error /**< Error code */ | 258 int *error |
65 ) OPUS_ARG_NONNULL(5); | 259 ) OPUS_ARG_NONNULL(5); |
66 | 260 |
67 /** Initialize an already allocated multistream encoder state. */ | 261 /** Initialize a previously allocated multistream encoder state. |
| 262 * The memory pointed to by \a st must be at least the size returned by |
| 263 * opus_multistream_encoder_get_size(). |
| 264 * This is intended for applications which use their own allocator instead of |
| 265 * malloc. |
| 266 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. |
| 267 * @see opus_multistream_encoder_create |
| 268 * @see opus_multistream_encoder_get_size |
| 269 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize. |
| 270 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz). |
| 271 * This must be one of 8000, 12000, 16000, |
| 272 * 24000, or 48000. |
| 273 * @param channels <tt>int</tt>: Number of channels in the input signal. |
| 274 * This must be at most 255. |
| 275 * It may be greater than the number of |
| 276 * coded channels (<code>streams + |
| 277 * coupled_streams</code>). |
| 278 * @param streams <tt>int</tt>: The total number of streams to encode from the |
| 279 * input. |
| 280 * This must be no more than the number of channel
s. |
| 281 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams |
| 282 * to encode. |
| 283 * This must be no larger than the total |
| 284 * number of streams. |
| 285 * Additionally, The total number of |
| 286 * encoded channels (<code>streams + |
| 287 * coupled_streams</code>) must be no |
| 288 * more than the number of input channels. |
| 289 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from |
| 290 * encoded channels to input channels, as described in |
| 291 * @ref opus_multistream. As an extra constraint, the |
| 292 * multistream encoder does not allow encoding coupled |
| 293 * streams for which one channel is unused since this |
| 294 * is never a good idea. |
| 295 * @param application <tt>int</tt>: The target encoder application. |
| 296 * This must be one of the following: |
| 297 * <dl> |
| 298 * <dt>#OPUS_APPLICATION_VOIP</dt> |
| 299 * <dd>Process signal for improved speech intelligibility.</dd> |
| 300 * <dt>#OPUS_APPLICATION_AUDIO</dt> |
| 301 * <dd>Favor faithfulness to the original input.</dd> |
| 302 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> |
| 303 * <dd>Configure the minimum possible coding delay by disabling certain modes |
| 304 * of operation.</dd> |
| 305 * </dl> |
| 306 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) |
| 307 * on failure. |
| 308 */ |
68 OPUS_EXPORT int opus_multistream_encoder_init( | 309 OPUS_EXPORT int opus_multistream_encoder_init( |
69 OpusMSEncoder *st, /**< Encoder state */ | 310 OpusMSEncoder *st, |
70 opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ | 311 opus_int32 Fs, |
71 int channels, /**< Number of channels in the input signal */ | 312 int channels, |
72 int streams, /**< Total number of streams to encode from the
input */ | 313 int streams, |
73 int coupled_streams, /**< Number of coupled (stereo) streams to encod
e */ | 314 int coupled_streams, |
74 const unsigned char *mapping, /**< Encoded mapping between channels and st
reams */ | 315 const unsigned char *mapping, |
75 int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APP
LICATION_AUDIO) */ | 316 int application |
76 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); | 317 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); |
77 | 318 |
78 /** Returns length of the data payload (in bytes) or a negative error code */ | 319 /** Encodes a multistream Opus frame. |
| 320 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. |
| 321 * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved |
| 322 * samples. |
| 323 * This must contain |
| 324 * <code>frame_size*channels</code> |
| 325 * samples. |
| 326 * @param frame_size <tt>int</tt>: Number of samples per channel in the input |
| 327 * signal. |
| 328 * This must be an Opus frame size for the |
| 329 * encoder's sampling rate. |
| 330 * For example, at 48 kHz the permitted values |
| 331 * are 120, 240, 480, 960, 1920, and 2880. |
| 332 * Passing in a duration of less than 10 ms |
| 333 * (480 samples at 48 kHz) will prevent the |
| 334 * encoder from using the LPC or hybrid modes. |
| 335 * @param[out] data <tt>unsigned char*</tt>: Output payload. |
| 336 * This must contain storage for at |
| 337 * least \a max_data_bytes. |
| 338 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated |
| 339 * memory for the output |
| 340 * payload. This may be |
| 341 * used to impose an upper limi
t on |
| 342 * the instant bitrate, but sho
uld |
| 343 * not be used as the only bitr
ate |
| 344 * control. Use #OPUS_SET_BITRA
TE to |
| 345 * control the bitrate. |
| 346 * @returns The length of the encoded packet (in bytes) on success or a |
| 347 * negative error code (see @ref opus_errorcodes) on failure. |
| 348 */ |
79 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( | 349 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( |
80 OpusMSEncoder *st, /**< Encoder state */ | 350 OpusMSEncoder *st, |
81 const opus_int16 *pcm, /**< Input signal as interleaved samples. Length
is frame_size*channels */ | 351 const opus_int16 *pcm, |
82 int frame_size, /**< Number of samples per frame of input signal
*/ | 352 int frame_size, |
83 unsigned char *data, /**< Output buffer for the compressed payload (n
o more than max_data_bytes long) */ | 353 unsigned char *data, |
84 opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for
controlling bitrate */ | 354 opus_int32 max_data_bytes |
85 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); | 355 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); |
86 | 356 |
87 /** Returns length of the data payload (in bytes) or a negative error code. */ | 357 /** Encodes a multistream Opus frame from floating point input. |
| 358 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. |
| 359 * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved |
| 360 * samples with a normal range of |
| 361 * +/-1.0. |
| 362 * Samples with a range beyond +/-1.0 |
| 363 * are supported but will be clipped by |
| 364 * decoders using the integer API and |
| 365 * should only be used if it is known |
| 366 * that the far end supports extended |
| 367 * dynamic range. |
| 368 * This must contain |
| 369 * <code>frame_size*channels</code> |
| 370 * samples. |
| 371 * @param frame_size <tt>int</tt>: Number of samples per channel in the input |
| 372 * signal. |
| 373 * This must be an Opus frame size for the |
| 374 * encoder's sampling rate. |
| 375 * For example, at 48 kHz the permitted values |
| 376 * are 120, 240, 480, 960, 1920, and 2880. |
| 377 * Passing in a duration of less than 10 ms |
| 378 * (480 samples at 48 kHz) will prevent the |
| 379 * encoder from using the LPC or hybrid modes. |
| 380 * @param[out] data <tt>unsigned char*</tt>: Output payload. |
| 381 * This must contain storage for at |
| 382 * least \a max_data_bytes. |
| 383 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated |
| 384 * memory for the output |
| 385 * payload. This may be |
| 386 * used to impose an upper limi
t on |
| 387 * the instant bitrate, but sho
uld |
| 388 * not be used as the only bitr
ate |
| 389 * control. Use #OPUS_SET_BITRA
TE to |
| 390 * control the bitrate. |
| 391 * @returns The length of the encoded packet (in bytes) on success or a |
| 392 * negative error code (see @ref opus_errorcodes) on failure. |
| 393 */ |
88 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( | 394 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( |
89 OpusMSEncoder *st, /**< Encoder state */ | 395 OpusMSEncoder *st, |
90 const float *pcm, /**< Input signal interleaved in channel order.
length is frame_size*channels */ | 396 const float *pcm, |
91 int frame_size, /**< Number of samples per frame of input signal
*/ | 397 int frame_size, |
92 unsigned char *data, /**< Output buffer for the compressed payload (n
o more than max_data_bytes long) */ | 398 unsigned char *data, |
93 opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for
controlling bitrate */ | 399 opus_int32 max_data_bytes |
94 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); | 400 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); |
95 | 401 |
96 /** Gets the size of an OpusMSEncoder structure. | 402 /** Frees an <code>OpusMSEncoder</code> allocated by |
97 * @returns size | 403 * opus_multistream_encoder_create(). |
98 */ | 404 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed. |
99 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size
( | 405 */ |
100 int streams, /**< Total number of coded streams */ | 406 OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); |
101 int coupled_streams /**< Number of coupled (stereo) streams */ | 407 |
| 408 /** Perform a CTL function on a multistream Opus encoder. |
| 409 * |
| 410 * Generally the request and subsequent arguments are generated by a |
| 411 * convenience macro. |
| 412 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. |
| 413 * @param request This and all remaining parameters should be replaced by one |
| 414 * of the convenience macros in @ref opus_genericctls, |
| 415 * @ref opus_encoderctls, or @ref opus_multistream_ctls. |
| 416 * @see opus_genericctls |
| 417 * @see opus_encoderctls |
| 418 * @see opus_multistream_ctls |
| 419 */ |
| 420 OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...
) OPUS_ARG_NONNULL(1); |
| 421 |
| 422 /**@}*/ |
| 423 |
| 424 /**\name Multistream decoder functions */ |
| 425 /**@{*/ |
| 426 |
| 427 /** Gets the size of an <code>OpusMSDecoder</code> structure. |
| 428 * @param streams <tt>int</tt>: The total number of streams coded in the |
| 429 * input. |
| 430 * This must be no more than 255. |
| 431 * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled |
| 432 * (2 channel) streams. |
| 433 * This must be no larger than the total |
| 434 * number of streams. |
| 435 * Additionally, The total number of |
| 436 * coded channels (<code>streams + |
| 437 * coupled_streams</code>) must be no |
| 438 * more than 255. |
| 439 * @returns The size in bytes on success, or a negative error code |
| 440 * (see @ref opus_errorcodes) on error. |
| 441 */ |
| 442 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size
( |
| 443 int streams, |
| 444 int coupled_streams |
102 ); | 445 ); |
103 | 446 |
104 /** Deallocate a multstream encoder state */ | 447 /** Allocates and initializes a multistream decoder state. |
105 OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); | 448 * Call opus_multistream_decoder_destroy() to release |
106 | 449 * this object when finished. |
107 /** Get or set options on a multistream encoder state */ | 450 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz). |
108 OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...
) OPUS_ARG_NONNULL(1); | 451 * This must be one of 8000, 12000, 16000, |
109 | 452 * 24000, or 48000. |
110 /** Allocate and initialize a multistream decoder state object. | 453 * @param channels <tt>int</tt>: Number of channels to output. |
111 * Call opus_multistream_decoder_destroy() to release | 454 * This must be at most 255. |
112 * this object when finished. */ | 455 * It may be different from the number of coded |
| 456 * channels (<code>streams + |
| 457 * coupled_streams</code>). |
| 458 * @param streams <tt>int</tt>: The total number of streams coded in the |
| 459 * input. |
| 460 * This must be no more than 255. |
| 461 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled |
| 462 * (2 channel) streams. |
| 463 * This must be no larger than the total |
| 464 * number of streams. |
| 465 * Additionally, The total number of |
| 466 * coded channels (<code>streams + |
| 467 * coupled_streams</code>) must be no |
| 468 * more than 255. |
| 469 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from |
| 470 * coded channels to output channels, as described in |
| 471 * @ref opus_multistream. |
| 472 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error |
| 473 * code (see @ref opus_errorcodes) on |
| 474 * failure. |
| 475 */ |
113 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_crea
te( | 476 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_crea
te( |
114 opus_int32 Fs, /**< Sampling rate to decode at (Hz) */ | 477 opus_int32 Fs, |
115 int channels, /**< Number of channels to decode */ | 478 int channels, |
116 int streams, /**< Total number of coded streams in the multis
tream */ | 479 int streams, |
117 int coupled_streams, /**< Number of coupled (stereo) streams in the m
ultistream */ | 480 int coupled_streams, |
118 const unsigned char *mapping, /**< Stream to channel mapping table */ | 481 const unsigned char *mapping, |
119 int *error /**< Error code */ | 482 int *error |
120 ) OPUS_ARG_NONNULL(5); | 483 ) OPUS_ARG_NONNULL(5); |
121 | 484 |
122 /** Intialize a previously allocated decoder state object. */ | 485 /** Intialize a previously allocated decoder state object. |
| 486 * The memory pointed to by \a st must be at least the size returned by |
| 487 * opus_multistream_encoder_get_size(). |
| 488 * This is intended for applications which use their own allocator instead of |
| 489 * malloc. |
| 490 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. |
| 491 * @see opus_multistream_decoder_create |
| 492 * @see opus_multistream_deocder_get_size |
| 493 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize. |
| 494 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz). |
| 495 * This must be one of 8000, 12000, 16000, |
| 496 * 24000, or 48000. |
| 497 * @param channels <tt>int</tt>: Number of channels to output. |
| 498 * This must be at most 255. |
| 499 * It may be different from the number of coded |
| 500 * channels (<code>streams + |
| 501 * coupled_streams</code>). |
| 502 * @param streams <tt>int</tt>: The total number of streams coded in the |
| 503 * input. |
| 504 * This must be no more than 255. |
| 505 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled |
| 506 * (2 channel) streams. |
| 507 * This must be no larger than the total |
| 508 * number of streams. |
| 509 * Additionally, The total number of |
| 510 * coded channels (<code>streams + |
| 511 * coupled_streams</code>) must be no |
| 512 * more than 255. |
| 513 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from |
| 514 * coded channels to output channels, as described in |
| 515 * @ref opus_multistream. |
| 516 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) |
| 517 * on failure. |
| 518 */ |
123 OPUS_EXPORT int opus_multistream_decoder_init( | 519 OPUS_EXPORT int opus_multistream_decoder_init( |
124 OpusMSDecoder *st, /**< Encoder state */ | 520 OpusMSDecoder *st, |
125 opus_int32 Fs, /**< Sample rate of input signal (Hz) */ | 521 opus_int32 Fs, |
126 int channels, /**< Number of channels in the input signal */ | 522 int channels, |
127 int streams, /**< Total number of coded streams */ | 523 int streams, |
128 int coupled_streams, /**< Number of coupled (stereo) streams */ | 524 int coupled_streams, |
129 const unsigned char *mapping /**< Stream to channel mapping table */ | 525 const unsigned char *mapping |
130 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); | 526 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); |
131 | 527 |
132 /** Returns the number of samples decoded or a negative error code */ | 528 /** Decode a multistream Opus packet. |
| 529 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. |
| 530 * @param[in] data <tt>const unsigned char*</tt>: Input payload. |
| 531 * Use a <code>NULL</code> |
| 532 * pointer to indicate packet |
| 533 * loss. |
| 534 * @param len <tt>opus_int32</tt>: Number of bytes in payload. |
| 535 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved |
| 536 * samples. |
| 537 * This must contain room for |
| 538 * <code>frame_size*channels</code> |
| 539 * samples. |
| 540 * @param frame_size <tt>int</tt>: The number of samples per channel of |
| 541 * available space in \a pcm. |
| 542 * If this is less than the maximum packet dura
tion |
| 543 * (120 ms; 5760 for 48kHz), this function will
not be capable |
| 544 * of decoding some packets. In the case of PLC
(data==NULL) |
| 545 * or FEC (decode_fec=1), then frame_size needs
to be exactly |
| 546 * the duration of audio that is missing, other
wise the |
| 547 * decoder will not be in the optimal state to
decode the |
| 548 * next incoming packet. For the PLC and FEC ca
ses, frame_size |
| 549 * <b>must</b> be a multiple of 2.5 ms. |
| 550 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band |
| 551 * forward error correction data be decoded. |
| 552 * If no such data is available, the frame is |
| 553 * decoded as if it were lost. |
| 554 * @returns Number of samples decoded on success or a negative error code |
| 555 * (see @ref opus_errorcodes) on failure. |
| 556 */ |
133 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( | 557 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( |
134 OpusMSDecoder *st, /**< Decoder state */ | 558 OpusMSDecoder *st, |
135 const unsigned char *data, /**< Input payload. Use a NULL pointer to indica
te packet loss */ | 559 const unsigned char *data, |
136 opus_int32 len, /**< Number of bytes in payload */ | 560 opus_int32 len, |
137 opus_int16 *pcm, /**< Output signal, samples interleaved in chann
el order . length is frame_size*channels */ | 561 opus_int16 *pcm, |
138 int frame_size, /**< Number of samples per frame of input signal
*/ | 562 int frame_size, |
139 int decode_fec /**< Flag (0/1) to request that any in-band forw
ard error correction data be */ | 563 int decode_fec |
140 /**< decoded. If no such data is available the f
rame is decoded as if it were lost. */ | |
141 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); | 564 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); |
142 | 565 |
143 /** Returns the number of samples decoded or a negative error code */ | 566 /** Decode a multistream Opus packet with floating point output. |
| 567 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. |
| 568 * @param[in] data <tt>const unsigned char*</tt>: Input payload. |
| 569 * Use a <code>NULL</code> |
| 570 * pointer to indicate packet |
| 571 * loss. |
| 572 * @param len <tt>opus_int32</tt>: Number of bytes in payload. |
| 573 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved |
| 574 * samples. |
| 575 * This must contain room for |
| 576 * <code>frame_size*channels</code> |
| 577 * samples. |
| 578 * @param frame_size <tt>int</tt>: The number of samples per channel of |
| 579 * available space in \a pcm. |
| 580 * If this is less than the maximum packet dura
tion |
| 581 * (120 ms; 5760 for 48kHz), this function will
not be capable |
| 582 * of decoding some packets. In the case of PLC
(data==NULL) |
| 583 * or FEC (decode_fec=1), then frame_size needs
to be exactly |
| 584 * the duration of audio that is missing, other
wise the |
| 585 * decoder will not be in the optimal state to
decode the |
| 586 * next incoming packet. For the PLC and FEC ca
ses, frame_size |
| 587 * <b>must</b> be a multiple of 2.5 ms. |
| 588 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band |
| 589 * forward error correction data be decoded. |
| 590 * If no such data is available, the frame is |
| 591 * decoded as if it were lost. |
| 592 * @returns Number of samples decoded on success or a negative error code |
| 593 * (see @ref opus_errorcodes) on failure. |
| 594 */ |
144 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( | 595 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( |
145 OpusMSDecoder *st, /**< Decoder state */ | 596 OpusMSDecoder *st, |
146 const unsigned char *data, /**< Input payload buffer. Use a NULL pointer to
indicate packet loss */ | 597 const unsigned char *data, |
147 opus_int32 len, /**< Number of payload bytes in data */ | 598 opus_int32 len, |
148 float *pcm, /**< Buffer for the output signal (interleaved i
in channel order). length is frame_size*channels */ | 599 float *pcm, |
149 int frame_size, /**< Number of samples per frame of input signal
*/ | 600 int frame_size, |
150 int decode_fec /**< Flag (0/1) to request that any in-band forw
ard error correction data be */ | 601 int decode_fec |
151 /**< decoded. If no such data is available the f
rame is decoded as if it were lost. */ | |
152 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); | 602 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); |
153 | 603 |
154 /** Gets the size of an OpusMSDecoder structure. | 604 /** Perform a CTL function on a multistream Opus decoder. |
155 * @returns size | 605 * |
156 */ | 606 * Generally the request and subsequent arguments are generated by a |
157 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size
( | 607 * convenience macro. |
158 int streams, /**< Total number of coded streams */ | 608 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state. |
159 int coupled_streams /**< Number of coupled (stereo) streams */ | 609 * @param request This and all remaining parameters should be replaced by one |
160 ); | 610 * of the convenience macros in @ref opus_genericctls, |
161 | 611 * @ref opus_decoderctls, or @ref opus_multistream_ctls. |
162 /** Get or set options on a multistream decoder state */ | 612 * @see opus_genericctls |
| 613 * @see opus_decoderctls |
| 614 * @see opus_multistream_ctls |
| 615 */ |
163 OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...
) OPUS_ARG_NONNULL(1); | 616 OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...
) OPUS_ARG_NONNULL(1); |
164 | 617 |
165 /** Deallocate a multistream decoder state object */ | 618 /** Frees an <code>OpusMSDecoder</code> allocated by |
| 619 * opus_multistream_decoder_create(). |
| 620 * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed. |
| 621 */ |
166 OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); | 622 OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); |
167 | 623 |
| 624 /**@}*/ |
| 625 |
| 626 /**@}*/ |
| 627 |
168 #ifdef __cplusplus | 628 #ifdef __cplusplus |
169 } | 629 } |
170 #endif | 630 #endif |
171 | 631 |
172 #endif /* OPUS_MULTISTREAM_H */ | 632 #endif /* OPUS_MULTISTREAM_H */ |
OLD | NEW |