annotate win32-msvc/include/opus/opus_custom.h @ 156:1bf23f5aebc4

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