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