media/libopus/include/opus_custom.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
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) 2007-2008 CSIRO
michael@0 2 Copyright (c) 2007-2009 Xiph.Org Foundation
michael@0 3 Copyright (c) 2008-2012 Gregory Maxwell
michael@0 4 Written by Jean-Marc Valin and Gregory Maxwell */
michael@0 5 /*
michael@0 6 Redistribution and use in source and binary forms, with or without
michael@0 7 modification, are permitted provided that the following conditions
michael@0 8 are met:
michael@0 9
michael@0 10 - Redistributions of source code must retain the above copyright
michael@0 11 notice, this list of conditions and the following disclaimer.
michael@0 12
michael@0 13 - Redistributions in binary form must reproduce the above copyright
michael@0 14 notice, this list of conditions and the following disclaimer in the
michael@0 15 documentation and/or other materials provided with the distribution.
michael@0 16
michael@0 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 18 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
michael@0 21 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 22 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 24 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 28 */
michael@0 29
michael@0 30 /**
michael@0 31 @file opus_custom.h
michael@0 32 @brief Opus-Custom reference implementation API
michael@0 33 */
michael@0 34
michael@0 35 #ifndef OPUS_CUSTOM_H
michael@0 36 #define OPUS_CUSTOM_H
michael@0 37
michael@0 38 #include "opus_defines.h"
michael@0 39
michael@0 40 #ifdef __cplusplus
michael@0 41 extern "C" {
michael@0 42 #endif
michael@0 43
michael@0 44 #ifdef CUSTOM_MODES
michael@0 45 # define OPUS_CUSTOM_EXPORT OPUS_EXPORT
michael@0 46 # define OPUS_CUSTOM_EXPORT_STATIC OPUS_EXPORT
michael@0 47 #else
michael@0 48 # define OPUS_CUSTOM_EXPORT
michael@0 49 # ifdef OPUS_BUILD
michael@0 50 # define OPUS_CUSTOM_EXPORT_STATIC static OPUS_INLINE
michael@0 51 # else
michael@0 52 # define OPUS_CUSTOM_EXPORT_STATIC
michael@0 53 # endif
michael@0 54 #endif
michael@0 55
michael@0 56 /** @defgroup opus_custom Opus Custom
michael@0 57 * @{
michael@0 58 * Opus Custom is an optional part of the Opus specification and
michael@0 59 * reference implementation which uses a distinct API from the regular
michael@0 60 * API and supports frame sizes that are not normally supported.\ Use
michael@0 61 * of Opus Custom is discouraged for all but very special applications
michael@0 62 * for which a frame size different from 2.5, 5, 10, or 20 ms is needed
michael@0 63 * (for either complexity or latency reasons) and where interoperability
michael@0 64 * is less important.
michael@0 65 *
michael@0 66 * In addition to the interoperability limitations the use of Opus custom
michael@0 67 * disables a substantial chunk of the codec and generally lowers the
michael@0 68 * quality available at a given bitrate. Normally when an application needs
michael@0 69 * a different frame size from the codec it should buffer to match the
michael@0 70 * sizes but this adds a small amount of delay which may be important
michael@0 71 * in some very low latency applications. Some transports (especially
michael@0 72 * constant rate RF transports) may also work best with frames of
michael@0 73 * particular durations.
michael@0 74 *
michael@0 75 * Libopus only supports custom modes if they are enabled at compile time.
michael@0 76 *
michael@0 77 * The Opus Custom API is similar to the regular API but the
michael@0 78 * @ref opus_encoder_create and @ref opus_decoder_create calls take
michael@0 79 * an additional mode parameter which is a structure produced by
michael@0 80 * a call to @ref opus_custom_mode_create. Both the encoder and decoder
michael@0 81 * must create a mode using the same sample rate (fs) and frame size
michael@0 82 * (frame size) so these parameters must either be signaled out of band
michael@0 83 * or fixed in a particular implementation.
michael@0 84 *
michael@0 85 * Similar to regular Opus the custom modes support on the fly frame size
michael@0 86 * switching, but the sizes available depend on the particular frame size in
michael@0 87 * use. For some initial frame sizes on a single on the fly size is available.
michael@0 88 */
michael@0 89
michael@0 90 /** Contains the state of an encoder. One encoder state is needed
michael@0 91 for each stream. It is initialized once at the beginning of the
michael@0 92 stream. Do *not* re-initialize the state for every frame.
michael@0 93 @brief Encoder state
michael@0 94 */
michael@0 95 typedef struct OpusCustomEncoder OpusCustomEncoder;
michael@0 96
michael@0 97 /** State of the decoder. One decoder state is needed for each stream.
michael@0 98 It is initialized once at the beginning of the stream. Do *not*
michael@0 99 re-initialize the state for every frame.
michael@0 100 @brief Decoder state
michael@0 101 */
michael@0 102 typedef struct OpusCustomDecoder OpusCustomDecoder;
michael@0 103
michael@0 104 /** The mode contains all the information necessary to create an
michael@0 105 encoder. Both the encoder and decoder need to be initialized
michael@0 106 with exactly the same mode, otherwise the output will be
michael@0 107 corrupted.
michael@0 108 @brief Mode configuration
michael@0 109 */
michael@0 110 typedef struct OpusCustomMode OpusCustomMode;
michael@0 111
michael@0 112 /** Creates a new mode struct. This will be passed to an encoder or
michael@0 113 * decoder. The mode MUST NOT BE DESTROYED until the encoders and
michael@0 114 * decoders that use it are destroyed as well.
michael@0 115 * @param [in] Fs <tt>int</tt>: Sampling rate (8000 to 96000 Hz)
michael@0 116 * @param [in] frame_size <tt>int</tt>: Number of samples (per channel) to encode in each
michael@0 117 * packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes)
michael@0 118 * @param [out] error <tt>int*</tt>: Returned error code (if NULL, no error will be returned)
michael@0 119 * @return A newly created mode
michael@0 120 */
michael@0 121 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error);
michael@0 122
michael@0 123 /** Destroys a mode struct. Only call this after all encoders and
michael@0 124 * decoders using this mode are destroyed as well.
michael@0 125 * @param [in] mode <tt>OpusCustomMode*</tt>: Mode to be freed.
michael@0 126 */
michael@0 127 OPUS_CUSTOM_EXPORT void opus_custom_mode_destroy(OpusCustomMode *mode);
michael@0 128
michael@0 129
michael@0 130 #if !defined(OPUS_BUILD) || defined(CELT_ENCODER_C)
michael@0 131
michael@0 132 /* Encoder */
michael@0 133 /** Gets the size of an OpusCustomEncoder structure.
michael@0 134 * @param [in] mode <tt>OpusCustomMode *</tt>: Mode configuration
michael@0 135 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 136 * @returns size
michael@0 137 */
michael@0 138 OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_encoder_get_size(
michael@0 139 const OpusCustomMode *mode,
michael@0 140 int channels
michael@0 141 ) OPUS_ARG_NONNULL(1);
michael@0 142
michael@0 143 # ifdef CUSTOM_MODES
michael@0 144 /** Initializes a previously allocated encoder state
michael@0 145 * The memory pointed to by st must be the size returned by opus_custom_encoder_get_size.
michael@0 146 * This is intended for applications which use their own allocator instead of malloc.
michael@0 147 * @see opus_custom_encoder_create(),opus_custom_encoder_get_size()
michael@0 148 * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
michael@0 149 * @param [in] st <tt>OpusCustomEncoder*</tt>: Encoder state
michael@0 150 * @param [in] mode <tt>OpusCustomMode *</tt>: Contains all the information about the characteristics of
michael@0 151 * the stream (must be the same characteristics as used for the
michael@0 152 * decoder)
michael@0 153 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 154 * @return OPUS_OK Success or @ref opus_errorcodes
michael@0 155 */
michael@0 156 OPUS_CUSTOM_EXPORT int opus_custom_encoder_init(
michael@0 157 OpusCustomEncoder *st,
michael@0 158 const OpusCustomMode *mode,
michael@0 159 int channels
michael@0 160 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
michael@0 161 # endif
michael@0 162 #endif
michael@0 163
michael@0 164
michael@0 165 /** Creates a new encoder state. Each stream needs its own encoder
michael@0 166 * state (can't be shared across simultaneous streams).
michael@0 167 * @param [in] mode <tt>OpusCustomMode*</tt>: Contains all the information about the characteristics of
michael@0 168 * the stream (must be the same characteristics as used for the
michael@0 169 * decoder)
michael@0 170 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 171 * @param [out] error <tt>int*</tt>: Returns an error code
michael@0 172 * @return Newly created encoder state.
michael@0 173 */
michael@0 174 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomEncoder *opus_custom_encoder_create(
michael@0 175 const OpusCustomMode *mode,
michael@0 176 int channels,
michael@0 177 int *error
michael@0 178 ) OPUS_ARG_NONNULL(1);
michael@0 179
michael@0 180
michael@0 181 /** Destroys a an encoder state.
michael@0 182 * @param[in] st <tt>OpusCustomEncoder*</tt>: State to be freed.
michael@0 183 */
michael@0 184 OPUS_CUSTOM_EXPORT void opus_custom_encoder_destroy(OpusCustomEncoder *st);
michael@0 185
michael@0 186 /** Encodes a frame of audio.
michael@0 187 * @param [in] st <tt>OpusCustomEncoder*</tt>: Encoder state
michael@0 188 * @param [in] pcm <tt>float*</tt>: PCM audio in float format, with a normal range of +/-1.0.
michael@0 189 * Samples with a range beyond +/-1.0 are supported but will
michael@0 190 * be clipped by decoders using the integer API and should
michael@0 191 * only be used if it is known that the far end supports
michael@0 192 * extended dynamic range. There must be exactly
michael@0 193 * frame_size samples per channel.
michael@0 194 * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
michael@0 195 * @param [out] compressed <tt>char *</tt>: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long.
michael@0 196 * @param [in] maxCompressedBytes <tt>int</tt>: Maximum number of bytes to use for compressing the frame
michael@0 197 * (can change from one frame to another)
michael@0 198 * @return Number of bytes written to "compressed".
michael@0 199 * If negative, an error has occurred (see error codes). It is IMPORTANT that
michael@0 200 * the length returned be somehow transmitted to the decoder. Otherwise, no
michael@0 201 * decoding is possible.
michael@0 202 */
michael@0 203 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode_float(
michael@0 204 OpusCustomEncoder *st,
michael@0 205 const float *pcm,
michael@0 206 int frame_size,
michael@0 207 unsigned char *compressed,
michael@0 208 int maxCompressedBytes
michael@0 209 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
michael@0 210
michael@0 211 /** Encodes a frame of audio.
michael@0 212 * @param [in] st <tt>OpusCustomEncoder*</tt>: Encoder state
michael@0 213 * @param [in] pcm <tt>opus_int16*</tt>: PCM audio in signed 16-bit format (native endian).
michael@0 214 * There must be exactly frame_size samples per channel.
michael@0 215 * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
michael@0 216 * @param [out] compressed <tt>char *</tt>: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long.
michael@0 217 * @param [in] maxCompressedBytes <tt>int</tt>: Maximum number of bytes to use for compressing the frame
michael@0 218 * (can change from one frame to another)
michael@0 219 * @return Number of bytes written to "compressed".
michael@0 220 * If negative, an error has occurred (see error codes). It is IMPORTANT that
michael@0 221 * the length returned be somehow transmitted to the decoder. Otherwise, no
michael@0 222 * decoding is possible.
michael@0 223 */
michael@0 224 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode(
michael@0 225 OpusCustomEncoder *st,
michael@0 226 const opus_int16 *pcm,
michael@0 227 int frame_size,
michael@0 228 unsigned char *compressed,
michael@0 229 int maxCompressedBytes
michael@0 230 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
michael@0 231
michael@0 232 /** Perform a CTL function on an Opus custom encoder.
michael@0 233 *
michael@0 234 * Generally the request and subsequent arguments are generated
michael@0 235 * by a convenience macro.
michael@0 236 * @see opus_encoderctls
michael@0 237 */
michael@0 238 OPUS_CUSTOM_EXPORT int opus_custom_encoder_ctl(OpusCustomEncoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1);
michael@0 239
michael@0 240
michael@0 241 #if !defined(OPUS_BUILD) || defined(CELT_DECODER_C)
michael@0 242 /* Decoder */
michael@0 243
michael@0 244 /** Gets the size of an OpusCustomDecoder structure.
michael@0 245 * @param [in] mode <tt>OpusCustomMode *</tt>: Mode configuration
michael@0 246 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 247 * @returns size
michael@0 248 */
michael@0 249 OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_decoder_get_size(
michael@0 250 const OpusCustomMode *mode,
michael@0 251 int channels
michael@0 252 ) OPUS_ARG_NONNULL(1);
michael@0 253
michael@0 254 /** Initializes a previously allocated decoder state
michael@0 255 * The memory pointed to by st must be the size returned by opus_custom_decoder_get_size.
michael@0 256 * This is intended for applications which use their own allocator instead of malloc.
michael@0 257 * @see opus_custom_decoder_create(),opus_custom_decoder_get_size()
michael@0 258 * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
michael@0 259 * @param [in] st <tt>OpusCustomDecoder*</tt>: Decoder state
michael@0 260 * @param [in] mode <tt>OpusCustomMode *</tt>: Contains all the information about the characteristics of
michael@0 261 * the stream (must be the same characteristics as used for the
michael@0 262 * encoder)
michael@0 263 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 264 * @return OPUS_OK Success or @ref opus_errorcodes
michael@0 265 */
michael@0 266 OPUS_CUSTOM_EXPORT_STATIC int opus_custom_decoder_init(
michael@0 267 OpusCustomDecoder *st,
michael@0 268 const OpusCustomMode *mode,
michael@0 269 int channels
michael@0 270 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
michael@0 271
michael@0 272 #endif
michael@0 273
michael@0 274
michael@0 275 /** Creates a new decoder state. Each stream needs its own decoder state (can't
michael@0 276 * be shared across simultaneous streams).
michael@0 277 * @param [in] mode <tt>OpusCustomMode</tt>: Contains all the information about the characteristics of the
michael@0 278 * stream (must be the same characteristics as used for the encoder)
michael@0 279 * @param [in] channels <tt>int</tt>: Number of channels
michael@0 280 * @param [out] error <tt>int*</tt>: Returns an error code
michael@0 281 * @return Newly created decoder state.
michael@0 282 */
michael@0 283 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomDecoder *opus_custom_decoder_create(
michael@0 284 const OpusCustomMode *mode,
michael@0 285 int channels,
michael@0 286 int *error
michael@0 287 ) OPUS_ARG_NONNULL(1);
michael@0 288
michael@0 289 /** Destroys a an decoder state.
michael@0 290 * @param[in] st <tt>OpusCustomDecoder*</tt>: State to be freed.
michael@0 291 */
michael@0 292 OPUS_CUSTOM_EXPORT void opus_custom_decoder_destroy(OpusCustomDecoder *st);
michael@0 293
michael@0 294 /** Decode an opus custom frame with floating point output
michael@0 295 * @param [in] st <tt>OpusCustomDecoder*</tt>: Decoder state
michael@0 296 * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
michael@0 297 * @param [in] len <tt>int</tt>: Number of bytes in payload
michael@0 298 * @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels). length
michael@0 299 * is frame_size*channels*sizeof(float)
michael@0 300 * @param [in] frame_size Number of samples per channel of available space in *pcm.
michael@0 301 * @returns Number of decoded samples or @ref opus_errorcodes
michael@0 302 */
michael@0 303 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode_float(
michael@0 304 OpusCustomDecoder *st,
michael@0 305 const unsigned char *data,
michael@0 306 int len,
michael@0 307 float *pcm,
michael@0 308 int frame_size
michael@0 309 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
michael@0 310
michael@0 311 /** Decode an opus custom frame
michael@0 312 * @param [in] st <tt>OpusCustomDecoder*</tt>: Decoder state
michael@0 313 * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
michael@0 314 * @param [in] len <tt>int</tt>: Number of bytes in payload
michael@0 315 * @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
michael@0 316 * is frame_size*channels*sizeof(opus_int16)
michael@0 317 * @param [in] frame_size Number of samples per channel of available space in *pcm.
michael@0 318 * @returns Number of decoded samples or @ref opus_errorcodes
michael@0 319 */
michael@0 320 OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode(
michael@0 321 OpusCustomDecoder *st,
michael@0 322 const unsigned char *data,
michael@0 323 int len,
michael@0 324 opus_int16 *pcm,
michael@0 325 int frame_size
michael@0 326 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
michael@0 327
michael@0 328 /** Perform a CTL function on an Opus custom decoder.
michael@0 329 *
michael@0 330 * Generally the request and subsequent arguments are generated
michael@0 331 * by a convenience macro.
michael@0 332 * @see opus_genericctls
michael@0 333 */
michael@0 334 OPUS_CUSTOM_EXPORT int opus_custom_decoder_ctl(OpusCustomDecoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1);
michael@0 335
michael@0 336 /**@}*/
michael@0 337
michael@0 338 #ifdef __cplusplus
michael@0 339 }
michael@0 340 #endif
michael@0 341
michael@0 342 #endif /* OPUS_CUSTOM_H */

mercurial