annotate win32-msvc/include/opus/opus_custom.h @ 70:9e21af8f0420

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