tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_CODECS_OPUS_OPUS_INTERFACE_H_ |
| 12 | #define MODULES_AUDIO_CODING_CODECS_OPUS_OPUS_INTERFACE_H_ |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 13 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 14 | #include <stddef.h> |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 15 | #include <stdint.h> |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 16 | |
Alex Luebs | eeb2765 | 2017-11-20 11:13:56 -0800 | [diff] [blame] | 17 | #include "modules/audio_coding/codecs/opus/opus_inst.h" |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | // Opaque wrapper types for the codec state. |
| 24 | typedef struct WebRtcOpusEncInst OpusEncInst; |
| 25 | typedef struct WebRtcOpusDecInst OpusDecInst; |
| 26 | |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 27 | /**************************************************************************** |
| 28 | * WebRtcOpus_EncoderCreate(...) |
| 29 | * |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 30 | * This function creates an Opus encoder that encodes mono or stereo. |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 31 | * |
| 32 | * Input: |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 33 | * - channels : number of channels; 1 or 2. |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 34 | * - application : 0 - VOIP applications. |
| 35 | * Favor speech intelligibility. |
| 36 | * 1 - Audio applications. |
| 37 | * Favor faithfulness to the original input. |
| 38 | * |
| 39 | * Output: |
| 40 | * - inst : a pointer to Encoder context that is created |
| 41 | * if success. |
| 42 | * |
| 43 | * Return value : 0 - Success |
| 44 | * -1 - Error |
| 45 | */ |
| 46 | int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 47 | size_t channels, |
minyue@webrtc.org | 7dba786 | 2015-01-20 16:01:50 +0000 | [diff] [blame] | 48 | int32_t application); |
| 49 | |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 50 | /**************************************************************************** |
| 51 | * WebRtcOpus_MultistreamEncoderCreate(...) |
| 52 | * |
| 53 | * This function creates an Opus encoder with any supported channel count. |
| 54 | * |
| 55 | * Input: |
Alex Loiko | e5b9416 | 2019-04-08 17:19:41 +0200 | [diff] [blame] | 56 | * - channels : number of channels in the input of the encoder. |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 57 | * - application : 0 - VOIP applications. |
| 58 | * Favor speech intelligibility. |
| 59 | * 1 - Audio applications. |
| 60 | * Favor faithfulness to the original input. |
Alex Loiko | e5b9416 | 2019-04-08 17:19:41 +0200 | [diff] [blame] | 61 | * - streams : number of streams, as described in RFC 7845. |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 62 | * - coupled_streams : number of coupled streams, as described in |
| 63 | * RFC 7845. |
| 64 | * - channel_mapping : the channel mapping; pointer to array of |
| 65 | * `channel` bytes, as described in RFC 7845. |
| 66 | * |
| 67 | * Output: |
| 68 | * - inst : a pointer to Encoder context that is created |
| 69 | * if success. |
| 70 | * |
| 71 | * Return value : 0 - Success |
| 72 | * -1 - Error |
| 73 | */ |
| 74 | int16_t WebRtcOpus_MultistreamEncoderCreate( |
| 75 | OpusEncInst** inst, |
| 76 | size_t channels, |
| 77 | int32_t application, |
Alex Loiko | e5b9416 | 2019-04-08 17:19:41 +0200 | [diff] [blame] | 78 | size_t streams, |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 79 | size_t coupled_streams, |
| 80 | const unsigned char* channel_mapping); |
| 81 | |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 82 | int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst); |
| 83 | |
| 84 | /**************************************************************************** |
| 85 | * WebRtcOpus_Encode(...) |
| 86 | * |
| 87 | * This function encodes audio as a series of Opus frames and inserts |
| 88 | * it into a packet. Input buffer can be any length. |
| 89 | * |
| 90 | * Input: |
| 91 | * - inst : Encoder context |
| 92 | * - audio_in : Input speech data buffer |
minyue@webrtc.org | ecbe0aa | 2013-08-12 06:48:09 +0000 | [diff] [blame] | 93 | * - samples : Samples per channel in audio_in |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 94 | * - length_encoded_buffer : Output buffer size |
| 95 | * |
| 96 | * Output: |
| 97 | * - encoded : Output compressed data buffer |
| 98 | * |
minyue@webrtc.org | 0ca768b | 2014-12-11 16:09:35 +0000 | [diff] [blame] | 99 | * Return value : >=0 - Length (in bytes) of coded data |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 100 | * -1 - Error |
| 101 | */ |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 102 | int WebRtcOpus_Encode(OpusEncInst* inst, |
| 103 | const int16_t* audio_in, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 104 | size_t samples, |
| 105 | size_t length_encoded_buffer, |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 106 | uint8_t* encoded); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 107 | |
| 108 | /**************************************************************************** |
| 109 | * WebRtcOpus_SetBitRate(...) |
| 110 | * |
| 111 | * This function adjusts the target bitrate of the encoder. |
| 112 | * |
| 113 | * Input: |
| 114 | * - inst : Encoder context |
| 115 | * - rate : New target bitrate |
| 116 | * |
| 117 | * Return value : 0 - Success |
| 118 | * -1 - Error |
| 119 | */ |
| 120 | int16_t WebRtcOpus_SetBitRate(OpusEncInst* inst, int32_t rate); |
| 121 | |
minyue@webrtc.org | 0454688 | 2014-03-07 08:55:48 +0000 | [diff] [blame] | 122 | /**************************************************************************** |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 123 | * WebRtcOpus_SetPacketLossRate(...) |
| 124 | * |
| 125 | * This function configures the encoder's expected packet loss percentage. |
| 126 | * |
| 127 | * Input: |
| 128 | * - inst : Encoder context |
| 129 | * - loss_rate : loss percentage in the range 0-100, inclusive. |
| 130 | * Return value : 0 - Success |
| 131 | * -1 - Error |
| 132 | */ |
| 133 | int16_t WebRtcOpus_SetPacketLossRate(OpusEncInst* inst, int32_t loss_rate); |
| 134 | |
minyue@webrtc.org | 0040a6e | 2014-08-04 14:41:57 +0000 | [diff] [blame] | 135 | /**************************************************************************** |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 136 | * WebRtcOpus_SetMaxPlaybackRate(...) |
minyue@webrtc.org | 0040a6e | 2014-08-04 14:41:57 +0000 | [diff] [blame] | 137 | * |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 138 | * Configures the maximum playback rate for encoding. Due to hardware |
| 139 | * limitations, the receiver may render audio up to a playback rate. Opus |
| 140 | * encoder can use this information to optimize for network usage and encoding |
| 141 | * complexity. This will affect the audio bandwidth in the coded audio. However, |
| 142 | * the input/output sample rate is not affected. |
minyue@webrtc.org | 0040a6e | 2014-08-04 14:41:57 +0000 | [diff] [blame] | 143 | * |
| 144 | * Input: |
| 145 | * - inst : Encoder context |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 146 | * - frequency_hz : Maximum playback rate in Hz. |
| 147 | * This parameter can take any value. The relation |
| 148 | * between the value and the Opus internal mode is |
| 149 | * as following: |
| 150 | * frequency_hz <= 8000 narrow band |
| 151 | * 8000 < frequency_hz <= 12000 medium band |
| 152 | * 12000 < frequency_hz <= 16000 wide band |
| 153 | * 16000 < frequency_hz <= 24000 super wide band |
| 154 | * frequency_hz > 24000 full band |
minyue@webrtc.org | 0040a6e | 2014-08-04 14:41:57 +0000 | [diff] [blame] | 155 | * Return value : 0 - Success |
| 156 | * -1 - Error |
| 157 | */ |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 158 | int16_t WebRtcOpus_SetMaxPlaybackRate(OpusEncInst* inst, int32_t frequency_hz); |
minyue@webrtc.org | 0040a6e | 2014-08-04 14:41:57 +0000 | [diff] [blame] | 159 | |
Alex Loiko | 7a3e43a | 2019-01-29 12:27:08 +0100 | [diff] [blame] | 160 | /**************************************************************************** |
| 161 | * WebRtcOpus_GetMaxPlaybackRate(...) |
| 162 | * |
| 163 | * Queries the maximum playback rate for encoding. If different single-stream |
| 164 | * encoders have different maximum playback rates, this function fails. |
| 165 | * |
| 166 | * Input: |
| 167 | * - inst : Encoder context. |
| 168 | * Output: |
| 169 | * - result_hz : The maximum playback rate in Hz. |
| 170 | * Return value : 0 - Success |
| 171 | * -1 - Error |
| 172 | */ |
| 173 | int16_t WebRtcOpus_GetMaxPlaybackRate(OpusEncInst* const inst, |
| 174 | int32_t* result_hz); |
| 175 | |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 176 | /* TODO(minyue): Check whether an API to check the FEC and the packet loss rate |
| 177 | * is needed. It might not be very useful since there are not many use cases and |
| 178 | * the caller can always maintain the states. */ |
| 179 | |
| 180 | /**************************************************************************** |
| 181 | * WebRtcOpus_EnableFec() |
| 182 | * |
| 183 | * This function enables FEC for encoding. |
| 184 | * |
| 185 | * Input: |
| 186 | * - inst : Encoder context |
| 187 | * |
| 188 | * Return value : 0 - Success |
| 189 | * -1 - Error |
| 190 | */ |
| 191 | int16_t WebRtcOpus_EnableFec(OpusEncInst* inst); |
| 192 | |
| 193 | /**************************************************************************** |
| 194 | * WebRtcOpus_DisableFec() |
| 195 | * |
| 196 | * This function disables FEC for encoding. |
| 197 | * |
| 198 | * Input: |
| 199 | * - inst : Encoder context |
| 200 | * |
| 201 | * Return value : 0 - Success |
| 202 | * -1 - Error |
| 203 | */ |
| 204 | int16_t WebRtcOpus_DisableFec(OpusEncInst* inst); |
| 205 | |
minyue@webrtc.org | 0ca768b | 2014-12-11 16:09:35 +0000 | [diff] [blame] | 206 | /**************************************************************************** |
| 207 | * WebRtcOpus_EnableDtx() |
| 208 | * |
| 209 | * This function enables Opus internal DTX for encoding. |
| 210 | * |
| 211 | * Input: |
| 212 | * - inst : Encoder context |
| 213 | * |
| 214 | * Return value : 0 - Success |
| 215 | * -1 - Error |
| 216 | */ |
| 217 | int16_t WebRtcOpus_EnableDtx(OpusEncInst* inst); |
| 218 | |
| 219 | /**************************************************************************** |
| 220 | * WebRtcOpus_DisableDtx() |
| 221 | * |
| 222 | * This function disables Opus internal DTX for encoding. |
| 223 | * |
| 224 | * Input: |
| 225 | * - inst : Encoder context |
| 226 | * |
| 227 | * Return value : 0 - Success |
| 228 | * -1 - Error |
| 229 | */ |
| 230 | int16_t WebRtcOpus_DisableDtx(OpusEncInst* inst); |
| 231 | |
soren | 28dc285 | 2017-04-06 05:48:36 -0700 | [diff] [blame] | 232 | /**************************************************************************** |
| 233 | * WebRtcOpus_EnableCbr() |
| 234 | * |
| 235 | * This function enables CBR for encoding. |
| 236 | * |
| 237 | * Input: |
| 238 | * - inst : Encoder context |
| 239 | * |
| 240 | * Return value : 0 - Success |
| 241 | * -1 - Error |
| 242 | */ |
| 243 | int16_t WebRtcOpus_EnableCbr(OpusEncInst* inst); |
| 244 | |
| 245 | /**************************************************************************** |
| 246 | * WebRtcOpus_DisableCbr() |
| 247 | * |
| 248 | * This function disables CBR for encoding. |
| 249 | * |
| 250 | * Input: |
| 251 | * - inst : Encoder context |
| 252 | * |
| 253 | * Return value : 0 - Success |
| 254 | * -1 - Error |
| 255 | */ |
| 256 | int16_t WebRtcOpus_DisableCbr(OpusEncInst* inst); |
| 257 | |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 258 | /* |
minyue@webrtc.org | 0454688 | 2014-03-07 08:55:48 +0000 | [diff] [blame] | 259 | * WebRtcOpus_SetComplexity(...) |
| 260 | * |
| 261 | * This function adjusts the computational complexity. The effect is the same as |
| 262 | * calling the complexity setting of Opus as an Opus encoder related CTL. |
| 263 | * |
| 264 | * Input: |
| 265 | * - inst : Encoder context |
| 266 | * - complexity : New target complexity (0-10, inclusive) |
| 267 | * |
| 268 | * Return value : 0 - Success |
| 269 | * -1 - Error |
| 270 | */ |
| 271 | int16_t WebRtcOpus_SetComplexity(OpusEncInst* inst, int32_t complexity); |
| 272 | |
minyue | c8299f9 | 2016-09-27 02:08:47 -0700 | [diff] [blame] | 273 | /* |
Alex Luebs | eeb2765 | 2017-11-20 11:13:56 -0800 | [diff] [blame] | 274 | * WebRtcOpus_GetBandwidth(...) |
| 275 | * |
| 276 | * This function returns the current bandwidth. |
| 277 | * |
| 278 | * Input: |
| 279 | * - inst : Encoder context |
| 280 | * |
| 281 | * Return value : Bandwidth - Success |
| 282 | * -1 - Error |
| 283 | */ |
| 284 | int32_t WebRtcOpus_GetBandwidth(OpusEncInst* inst); |
| 285 | |
| 286 | /* |
| 287 | * WebRtcOpus_SetBandwidth(...) |
| 288 | * |
| 289 | * By default Opus decides which bandwidth to encode the signal in depending on |
| 290 | * the the bitrate. This function overrules the previous setting and forces the |
| 291 | * encoder to encode in narrowband/wideband/fullband/etc. |
| 292 | * |
| 293 | * Input: |
| 294 | * - inst : Encoder context |
| 295 | * - bandwidth : New target bandwidth. Valid values are: |
| 296 | * OPUS_BANDWIDTH_NARROWBAND |
| 297 | * OPUS_BANDWIDTH_MEDIUMBAND |
| 298 | * OPUS_BANDWIDTH_WIDEBAND |
| 299 | * OPUS_BANDWIDTH_SUPERWIDEBAND |
| 300 | * OPUS_BANDWIDTH_FULLBAND |
| 301 | * |
| 302 | * Return value : 0 - Success |
| 303 | * -1 - Error |
| 304 | */ |
| 305 | int16_t WebRtcOpus_SetBandwidth(OpusEncInst* inst, int32_t bandwidth); |
| 306 | |
| 307 | /* |
minyue | c8299f9 | 2016-09-27 02:08:47 -0700 | [diff] [blame] | 308 | * WebRtcOpus_SetForceChannels(...) |
| 309 | * |
| 310 | * If the encoder is initialized as a stereo encoder, Opus will by default |
| 311 | * decide whether to encode in mono or stereo based on the bitrate. This |
| 312 | * function overrules the previous setting, and forces the encoder to encode |
| 313 | * in auto/mono/stereo. |
| 314 | * |
| 315 | * If the Encoder is initialized as a mono encoder, and one tries to force |
| 316 | * stereo, the function will return an error. |
| 317 | * |
| 318 | * Input: |
| 319 | * - inst : Encoder context |
| 320 | * - num_channels : 0 - Not forced |
| 321 | * 1 - Mono |
| 322 | * 2 - Stereo |
| 323 | * |
| 324 | * Return value : 0 - Success |
| 325 | * -1 - Error |
| 326 | */ |
minyue | 41b9c80 | 2016-10-06 07:13:54 -0700 | [diff] [blame] | 327 | int16_t WebRtcOpus_SetForceChannels(OpusEncInst* inst, size_t num_channels); |
minyue | c8299f9 | 2016-09-27 02:08:47 -0700 | [diff] [blame] | 328 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 329 | int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, size_t channels); |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 330 | |
| 331 | /**************************************************************************** |
| 332 | * WebRtcOpus_MultistreamDecoderCreate(...) |
| 333 | * |
| 334 | * This function creates an Opus decoder with any supported channel count. |
| 335 | * |
| 336 | * Input: |
Alex Loiko | e5b9416 | 2019-04-08 17:19:41 +0200 | [diff] [blame] | 337 | * - channels : number of output channels that the decoder |
| 338 | * will produce. |
| 339 | * - streams : number of encoded streams, as described in |
| 340 | * RFC 7845. |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 341 | * - coupled_streams : number of coupled streams, as described in |
| 342 | * RFC 7845. |
| 343 | * - channel_mapping : the channel mapping; pointer to array of |
| 344 | * `channel` bytes, as described in RFC 7845. |
| 345 | * |
| 346 | * Output: |
| 347 | * - inst : a pointer to a Decoder context that is created |
| 348 | * if success. |
| 349 | * |
| 350 | * Return value : 0 - Success |
| 351 | * -1 - Error |
| 352 | */ |
| 353 | int16_t WebRtcOpus_MultistreamDecoderCreate( |
| 354 | OpusDecInst** inst, |
| 355 | size_t channels, |
Alex Loiko | e5b9416 | 2019-04-08 17:19:41 +0200 | [diff] [blame] | 356 | size_t streams, |
Alex Loiko | 50b8c39 | 2019-04-03 15:12:01 +0200 | [diff] [blame] | 357 | size_t coupled_streams, |
| 358 | const unsigned char* channel_mapping); |
| 359 | |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 360 | int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst); |
| 361 | |
| 362 | /**************************************************************************** |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 363 | * WebRtcOpus_DecoderChannels(...) |
| 364 | * |
| 365 | * This function returns the number of channels created for Opus decoder. |
| 366 | */ |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 367 | size_t WebRtcOpus_DecoderChannels(OpusDecInst* inst); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 368 | |
| 369 | /**************************************************************************** |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 370 | * WebRtcOpus_DecoderInit(...) |
| 371 | * |
| 372 | * This function resets state of the decoder. |
| 373 | * |
| 374 | * Input: |
| 375 | * - inst : Decoder context |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 376 | */ |
Karl Wiberg | 4376648 | 2015-08-27 15:22:11 +0200 | [diff] [blame] | 377 | void WebRtcOpus_DecoderInit(OpusDecInst* inst); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 378 | |
| 379 | /**************************************************************************** |
| 380 | * WebRtcOpus_Decode(...) |
| 381 | * |
| 382 | * This function decodes an Opus packet into one or more audio frames at the |
| 383 | * ACM interface's sampling rate (32 kHz). |
| 384 | * |
| 385 | * Input: |
| 386 | * - inst : Decoder context |
| 387 | * - encoded : Encoded data |
| 388 | * - encoded_bytes : Bytes in encoded vector |
| 389 | * |
| 390 | * Output: |
| 391 | * - decoded : The decoded vector |
| 392 | * - audio_type : 1 normal, 2 CNG (for Opus it should |
| 393 | * always return 1 since we're not using Opus's |
| 394 | * built-in DTX/CNG scheme) |
| 395 | * |
minyue@webrtc.org | ecbe0aa | 2013-08-12 06:48:09 +0000 | [diff] [blame] | 396 | * Return value : >0 - Samples per channel in decoded vector |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 397 | * -1 - Error |
| 398 | */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 399 | int WebRtcOpus_Decode(OpusDecInst* inst, |
| 400 | const uint8_t* encoded, |
| 401 | size_t encoded_bytes, |
| 402 | int16_t* decoded, |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 403 | int16_t* audio_type); |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 404 | |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 405 | /**************************************************************************** |
| 406 | * WebRtcOpus_DecodePlc(...) |
| 407 | * |
tina.legrand@webrtc.org | bd21fb5 | 2013-08-08 11:01:07 +0000 | [diff] [blame] | 408 | * This function processes PLC for opus frame(s). |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 409 | * Input: |
| 410 | * - inst : Decoder context |
| 411 | * - number_of_lost_frames : Number of PLC frames to produce |
| 412 | * |
| 413 | * Output: |
| 414 | * - decoded : The decoded vector |
| 415 | * |
| 416 | * Return value : >0 - number of samples in decoded PLC vector |
| 417 | * -1 - Error |
| 418 | */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 419 | int WebRtcOpus_DecodePlc(OpusDecInst* inst, |
| 420 | int16_t* decoded, |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 421 | int number_of_lost_frames); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 422 | |
tina.legrand@webrtc.org | 4275ab1 | 2012-12-19 09:52:45 +0000 | [diff] [blame] | 423 | /**************************************************************************** |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 424 | * WebRtcOpus_DecodeFec(...) |
| 425 | * |
| 426 | * This function decodes the FEC data from an Opus packet into one or more audio |
| 427 | * frames at the ACM interface's sampling rate (32 kHz). |
| 428 | * |
| 429 | * Input: |
| 430 | * - inst : Decoder context |
| 431 | * - encoded : Encoded data |
| 432 | * - encoded_bytes : Bytes in encoded vector |
| 433 | * |
| 434 | * Output: |
| 435 | * - decoded : The decoded vector (previous frame) |
| 436 | * |
| 437 | * Return value : >0 - Samples per channel in decoded vector |
| 438 | * 0 - No FEC data in the packet |
| 439 | * -1 - Error |
| 440 | */ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 441 | int WebRtcOpus_DecodeFec(OpusDecInst* inst, |
| 442 | const uint8_t* encoded, |
| 443 | size_t encoded_bytes, |
| 444 | int16_t* decoded, |
Peter Kasting | bba7807 | 2015-06-11 19:02:46 -0700 | [diff] [blame] | 445 | int16_t* audio_type); |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 446 | |
| 447 | /**************************************************************************** |
tina.legrand@webrtc.org | 4275ab1 | 2012-12-19 09:52:45 +0000 | [diff] [blame] | 448 | * WebRtcOpus_DurationEst(...) |
| 449 | * |
| 450 | * This function calculates the duration of an opus packet. |
| 451 | * Input: |
| 452 | * - inst : Decoder context |
| 453 | * - payload : Encoded data pointer |
| 454 | * - payload_length_bytes : Bytes of encoded data |
| 455 | * |
Minyue | 323b132 | 2015-05-25 13:49:37 +0200 | [diff] [blame] | 456 | * Return value : The duration of the packet, in samples per |
| 457 | * channel. |
tina.legrand@webrtc.org | 4275ab1 | 2012-12-19 09:52:45 +0000 | [diff] [blame] | 458 | */ |
| 459 | int WebRtcOpus_DurationEst(OpusDecInst* inst, |
| 460 | const uint8_t* payload, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 461 | size_t payload_length_bytes); |
tina.legrand@webrtc.org | 4275ab1 | 2012-12-19 09:52:45 +0000 | [diff] [blame] | 462 | |
minyuel | 6d92bf5 | 2015-09-23 15:20:39 +0200 | [diff] [blame] | 463 | /**************************************************************************** |
| 464 | * WebRtcOpus_PlcDuration(...) |
| 465 | * |
| 466 | * This function calculates the duration of a frame returned by packet loss |
| 467 | * concealment (PLC). |
| 468 | * |
| 469 | * Input: |
| 470 | * - inst : Decoder context |
| 471 | * |
| 472 | * Return value : The duration of a frame returned by PLC, in |
| 473 | * samples per channel. |
| 474 | */ |
| 475 | int WebRtcOpus_PlcDuration(OpusDecInst* inst); |
| 476 | |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 477 | /* TODO(minyue): Check whether it is needed to add a decoder context to the |
| 478 | * arguments, like WebRtcOpus_DurationEst(...). In fact, the packet itself tells |
| 479 | * the duration. The decoder context in WebRtcOpus_DurationEst(...) is not used. |
| 480 | * So it may be advisable to remove it from WebRtcOpus_DurationEst(...). */ |
| 481 | |
| 482 | /**************************************************************************** |
| 483 | * WebRtcOpus_FecDurationEst(...) |
| 484 | * |
| 485 | * This function calculates the duration of the FEC data within an opus packet. |
| 486 | * Input: |
| 487 | * - payload : Encoded data pointer |
| 488 | * - payload_length_bytes : Bytes of encoded data |
| 489 | * |
| 490 | * Return value : >0 - The duration of the FEC data in the |
Minyue | 323b132 | 2015-05-25 13:49:37 +0200 | [diff] [blame] | 491 | * packet in samples per channel. |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 492 | * 0 - No FEC data in the packet. |
| 493 | */ |
| 494 | int WebRtcOpus_FecDurationEst(const uint8_t* payload, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 495 | size_t payload_length_bytes); |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 496 | |
| 497 | /**************************************************************************** |
| 498 | * WebRtcOpus_PacketHasFec(...) |
| 499 | * |
| 500 | * This function detects if an opus packet has FEC. |
| 501 | * Input: |
| 502 | * - payload : Encoded data pointer |
| 503 | * - payload_length_bytes : Bytes of encoded data |
| 504 | * |
| 505 | * Return value : 0 - the packet does NOT contain FEC. |
| 506 | * 1 - the packet contains FEC. |
| 507 | */ |
| 508 | int WebRtcOpus_PacketHasFec(const uint8_t* payload, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 509 | size_t payload_length_bytes); |
minyue@webrtc.org | 46509c8 | 2014-03-07 11:49:11 +0000 | [diff] [blame] | 510 | |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 511 | #ifdef __cplusplus |
| 512 | } // extern "C" |
| 513 | #endif |
| 514 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 515 | #endif // MODULES_AUDIO_CODING_CODECS_OPUS_OPUS_INTERFACE_H_ |