annotate osx/include/opus/opus_custom.h @ 169:223a55898ab9 tip default

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