annotate osx/include/opus/opus_custom.h @ 83:ae30d91d2ffe

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