kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [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_INCLUDE_AUDIO_CODING_MODULE_H_ |
| 12 | #define MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 13 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 14 | #include <memory> |
henrik.lundin | 4cf61dd | 2015-12-09 06:20:58 -0800 | [diff] [blame] | 15 | #include <string> |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 19 | #include "api/audio_codecs/audio_encoder.h" |
| 20 | #include "api/optional.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 21 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 23 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 24 | #include "modules/include/module.h" |
| 25 | #include "rtc_base/deprecation.h" |
| 26 | #include "rtc_base/function_view.h" |
| 27 | #include "system_wrappers/include/clock.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 28 | #include "typedefs.h" // NOLINT(build/include) |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
| 32 | // forward declarations |
| 33 | struct CodecInst; |
| 34 | struct WebRtcRTPHeader; |
| 35 | class AudioDecoder; |
| 36 | class AudioEncoder; |
| 37 | class AudioFrame; |
| 38 | class RTPFragmentationHeader; |
| 39 | |
| 40 | #define WEBRTC_10MS_PCM_AUDIO 960 // 16 bits super wideband 48 kHz |
| 41 | |
| 42 | // Callback class used for sending data ready to be packetized |
| 43 | class AudioPacketizationCallback { |
| 44 | public: |
| 45 | virtual ~AudioPacketizationCallback() {} |
| 46 | |
| 47 | virtual int32_t SendData(FrameType frame_type, |
| 48 | uint8_t payload_type, |
| 49 | uint32_t timestamp, |
| 50 | const uint8_t* payload_data, |
| 51 | size_t payload_len_bytes, |
| 52 | const RTPFragmentationHeader* fragmentation) = 0; |
| 53 | }; |
| 54 | |
| 55 | // Callback class used for reporting VAD decision |
| 56 | class ACMVADCallback { |
| 57 | public: |
| 58 | virtual ~ACMVADCallback() {} |
| 59 | |
| 60 | virtual int32_t InFrameType(FrameType frame_type) = 0; |
| 61 | }; |
| 62 | |
| 63 | class AudioCodingModule { |
| 64 | protected: |
| 65 | AudioCodingModule() {} |
| 66 | |
| 67 | public: |
| 68 | struct Config { |
kwiberg | 36a4388 | 2016-08-29 05:33:32 -0700 | [diff] [blame] | 69 | Config(); |
| 70 | Config(const Config&); |
| 71 | ~Config(); |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 72 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 73 | NetEq::Config neteq_config; |
| 74 | Clock* clock; |
ossu | e352578 | 2016-05-25 07:37:43 -0700 | [diff] [blame] | 75 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory; |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /////////////////////////////////////////////////////////////////////////// |
| 79 | // Creation and destruction of a ACM. |
| 80 | // |
| 81 | // The second method is used for testing where a simulated clock can be |
| 82 | // injected into ACM. ACM will take the ownership of the object clock and |
| 83 | // delete it when destroyed. |
| 84 | // |
solenberg | c7b4a45 | 2017-09-28 07:37:11 -0700 | [diff] [blame] | 85 | // TODO(solenberg): Remove once downstream projects are updated. |
| 86 | RTC_DEPRECATED static AudioCodingModule* Create(int id); |
| 87 | static AudioCodingModule* Create(); |
| 88 | static AudioCodingModule* Create(Clock* clock); |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 89 | static AudioCodingModule* Create(const Config& config); |
| 90 | virtual ~AudioCodingModule() = default; |
| 91 | |
| 92 | /////////////////////////////////////////////////////////////////////////// |
| 93 | // Utility functions |
| 94 | // |
| 95 | |
| 96 | /////////////////////////////////////////////////////////////////////////// |
| 97 | // uint8_t NumberOfCodecs() |
| 98 | // Returns number of supported codecs. |
| 99 | // |
| 100 | // Return value: |
| 101 | // number of supported codecs. |
| 102 | /// |
| 103 | static int NumberOfCodecs(); |
| 104 | |
| 105 | /////////////////////////////////////////////////////////////////////////// |
| 106 | // int32_t Codec() |
| 107 | // Get supported codec with list number. |
| 108 | // |
| 109 | // Input: |
| 110 | // -list_id : list number. |
| 111 | // |
| 112 | // Output: |
| 113 | // -codec : a structure where the parameters of the codec, |
| 114 | // given by list number is written to. |
| 115 | // |
| 116 | // Return value: |
| 117 | // -1 if the list number (list_id) is invalid. |
| 118 | // 0 if succeeded. |
| 119 | // |
| 120 | static int Codec(int list_id, CodecInst* codec); |
| 121 | |
| 122 | /////////////////////////////////////////////////////////////////////////// |
| 123 | // int32_t Codec() |
| 124 | // Get supported codec with the given codec name, sampling frequency, and |
| 125 | // a given number of channels. |
| 126 | // |
| 127 | // Input: |
| 128 | // -payload_name : name of the codec. |
| 129 | // -sampling_freq_hz : sampling frequency of the codec. Note! for RED |
| 130 | // a sampling frequency of -1 is a valid input. |
| 131 | // -channels : number of channels ( 1 - mono, 2 - stereo). |
| 132 | // |
| 133 | // Output: |
| 134 | // -codec : a structure where the function returns the |
| 135 | // default parameters of the codec. |
| 136 | // |
| 137 | // Return value: |
| 138 | // -1 if no codec matches the given parameters. |
| 139 | // 0 if succeeded. |
| 140 | // |
| 141 | static int Codec(const char* payload_name, CodecInst* codec, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 142 | int sampling_freq_hz, size_t channels); |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 143 | |
| 144 | /////////////////////////////////////////////////////////////////////////// |
| 145 | // int32_t Codec() |
| 146 | // |
| 147 | // Returns the list number of the given codec name, sampling frequency, and |
| 148 | // a given number of channels. |
| 149 | // |
| 150 | // Input: |
| 151 | // -payload_name : name of the codec. |
| 152 | // -sampling_freq_hz : sampling frequency of the codec. Note! for RED |
| 153 | // a sampling frequency of -1 is a valid input. |
| 154 | // -channels : number of channels ( 1 - mono, 2 - stereo). |
| 155 | // |
| 156 | // Return value: |
| 157 | // if the codec is found, the index of the codec in the list, |
| 158 | // -1 if the codec is not found. |
| 159 | // |
| 160 | static int Codec(const char* payload_name, int sampling_freq_hz, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 161 | size_t channels); |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 162 | |
| 163 | /////////////////////////////////////////////////////////////////////////// |
| 164 | // bool IsCodecValid() |
| 165 | // Checks the validity of the parameters of the given codec. |
| 166 | // |
| 167 | // Input: |
| 168 | // -codec : the structure which keeps the parameters of the |
| 169 | // codec. |
| 170 | // |
| 171 | // Return value: |
| 172 | // true if the parameters are valid, |
| 173 | // false if any parameter is not valid. |
| 174 | // |
| 175 | static bool IsCodecValid(const CodecInst& codec); |
| 176 | |
| 177 | /////////////////////////////////////////////////////////////////////////// |
| 178 | // Sender |
| 179 | // |
| 180 | |
| 181 | /////////////////////////////////////////////////////////////////////////// |
| 182 | // int32_t RegisterSendCodec() |
| 183 | // Registers a codec, specified by |send_codec|, as sending codec. |
| 184 | // This API can be called multiple of times to register Codec. The last codec |
| 185 | // registered overwrites the previous ones. |
| 186 | // The API can also be used to change payload type for CNG and RED, which are |
| 187 | // registered by default to default payload types. |
| 188 | // Note that registering CNG and RED won't overwrite speech codecs. |
| 189 | // This API can be called to set/change the send payload-type, frame-size |
| 190 | // or encoding rate (if applicable for the codec). |
| 191 | // |
| 192 | // Note: If a stereo codec is registered as send codec, VAD/DTX will |
| 193 | // automatically be turned off, since it is not supported for stereo sending. |
| 194 | // |
| 195 | // Note: If a secondary encoder is already registered, and the new send-codec |
| 196 | // has a sampling rate that does not match the secondary encoder, the |
| 197 | // secondary encoder will be unregistered. |
| 198 | // |
| 199 | // Input: |
| 200 | // -send_codec : Parameters of the codec to be registered, c.f. |
| 201 | // common_types.h for the definition of |
| 202 | // CodecInst. |
| 203 | // |
| 204 | // Return value: |
| 205 | // -1 if failed to initialize, |
| 206 | // 0 if succeeded. |
| 207 | // |
| 208 | virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0; |
| 209 | |
| 210 | // Registers |external_speech_encoder| as encoder. The new encoder will |
| 211 | // replace any previously registered speech encoder (internal or external). |
| 212 | virtual void RegisterExternalSendCodec( |
| 213 | AudioEncoder* external_speech_encoder) = 0; |
| 214 | |
kwiberg | 4cdbd57 | 2016-03-30 03:10:05 -0700 | [diff] [blame] | 215 | // |modifier| is called exactly once with one argument: a pointer to the |
| 216 | // unique_ptr that holds the current encoder (which is null if there is no |
| 217 | // current encoder). For the duration of the call, |modifier| has exclusive |
| 218 | // access to the unique_ptr; it may call the encoder, steal the encoder and |
| 219 | // replace it with another encoder or with nullptr, etc. |
| 220 | virtual void ModifyEncoder( |
kwiberg | 24c7c12 | 2016-09-28 11:57:10 -0700 | [diff] [blame] | 221 | rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0; |
kwiberg | 4cdbd57 | 2016-03-30 03:10:05 -0700 | [diff] [blame] | 222 | |
ivoc | 85228d6 | 2016-07-27 04:53:47 -0700 | [diff] [blame] | 223 | // |modifier| is called exactly once with one argument: a const pointer to the |
| 224 | // current encoder (which is null if there is no current encoder). |
kwiberg | 24c7c12 | 2016-09-28 11:57:10 -0700 | [diff] [blame] | 225 | virtual void QueryEncoder( |
| 226 | rtc::FunctionView<void(AudioEncoder const*)> query) = 0; |
ivoc | 85228d6 | 2016-07-27 04:53:47 -0700 | [diff] [blame] | 227 | |
kwiberg | 4cdbd57 | 2016-03-30 03:10:05 -0700 | [diff] [blame] | 228 | // Utility method for simply replacing the existing encoder with a new one. |
| 229 | void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) { |
| 230 | ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
| 231 | *encoder = std::move(new_encoder); |
| 232 | }); |
| 233 | } |
| 234 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 235 | /////////////////////////////////////////////////////////////////////////// |
| 236 | // int32_t SendCodec() |
| 237 | // Get parameters for the codec currently registered as send codec. |
| 238 | // |
| 239 | // Return value: |
| 240 | // The send codec, or nothing if we don't have one |
| 241 | // |
| 242 | virtual rtc::Optional<CodecInst> SendCodec() const = 0; |
| 243 | |
| 244 | /////////////////////////////////////////////////////////////////////////// |
| 245 | // int32_t SendFrequency() |
| 246 | // Get the sampling frequency of the current encoder in Hertz. |
| 247 | // |
| 248 | // Return value: |
| 249 | // positive; sampling frequency [Hz] of the current encoder. |
| 250 | // -1 if an error has happened. |
| 251 | // |
| 252 | virtual int32_t SendFrequency() const = 0; |
| 253 | |
| 254 | /////////////////////////////////////////////////////////////////////////// |
| 255 | // Sets the bitrate to the specified value in bits/sec. If the value is not |
| 256 | // supported by the codec, it will choose another appropriate value. |
minyue | 7e30432 | 2016-10-12 05:00:55 -0700 | [diff] [blame] | 257 | // |
| 258 | // This is only used in test code that rely on old ACM APIs. |
| 259 | // TODO(minyue): Remove it when possible. |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 260 | virtual void SetBitRate(int bitrate_bps) = 0; |
| 261 | |
| 262 | // int32_t RegisterTransportCallback() |
| 263 | // Register a transport callback which will be called to deliver |
| 264 | // the encoded buffers whenever Process() is called and a |
| 265 | // bit-stream is ready. |
| 266 | // |
| 267 | // Input: |
| 268 | // -transport : pointer to the callback class |
| 269 | // transport->SendData() is called whenever |
| 270 | // Process() is called and bit-stream is ready |
| 271 | // to deliver. |
| 272 | // |
| 273 | // Return value: |
| 274 | // -1 if the transport callback could not be registered |
| 275 | // 0 if registration is successful. |
| 276 | // |
| 277 | virtual int32_t RegisterTransportCallback( |
| 278 | AudioPacketizationCallback* transport) = 0; |
| 279 | |
| 280 | /////////////////////////////////////////////////////////////////////////// |
| 281 | // int32_t Add10MsData() |
| 282 | // Add 10MS of raw (PCM) audio data and encode it. If the sampling |
| 283 | // frequency of the audio does not match the sampling frequency of the |
| 284 | // current encoder ACM will resample the audio. If an encoded packet was |
| 285 | // produced, it will be delivered via the callback object registered using |
| 286 | // RegisterTransportCallback, and the return value from this function will |
| 287 | // be the number of bytes encoded. |
| 288 | // |
| 289 | // Input: |
| 290 | // -audio_frame : the input audio frame, containing raw audio |
| 291 | // sampling frequency etc., |
| 292 | // c.f. module_common_types.h for definition of |
| 293 | // AudioFrame. |
| 294 | // |
| 295 | // Return value: |
| 296 | // >= 0 number of bytes encoded. |
| 297 | // -1 some error occurred. |
| 298 | // |
| 299 | virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0; |
| 300 | |
| 301 | /////////////////////////////////////////////////////////////////////////// |
| 302 | // (RED) Redundant Coding |
| 303 | // |
| 304 | |
| 305 | /////////////////////////////////////////////////////////////////////////// |
| 306 | // int32_t SetREDStatus() |
| 307 | // configure RED status i.e. on/off. |
| 308 | // |
| 309 | // RFC 2198 describes a solution which has a single payload type which |
| 310 | // signifies a packet with redundancy. That packet then becomes a container, |
| 311 | // encapsulating multiple payloads into a single RTP packet. |
| 312 | // Such a scheme is flexible, since any amount of redundancy may be |
| 313 | // encapsulated within a single packet. There is, however, a small overhead |
| 314 | // since each encapsulated payload must be preceded by a header indicating |
| 315 | // the type of data enclosed. |
| 316 | // |
| 317 | // Input: |
| 318 | // -enable_red : if true RED is enabled, otherwise RED is |
| 319 | // disabled. |
| 320 | // |
| 321 | // Return value: |
| 322 | // -1 if failed to set RED status, |
| 323 | // 0 if succeeded. |
| 324 | // |
| 325 | virtual int32_t SetREDStatus(bool enable_red) = 0; |
| 326 | |
| 327 | /////////////////////////////////////////////////////////////////////////// |
| 328 | // bool REDStatus() |
| 329 | // Get RED status |
| 330 | // |
| 331 | // Return value: |
| 332 | // true if RED is enabled, |
| 333 | // false if RED is disabled. |
| 334 | // |
| 335 | virtual bool REDStatus() const = 0; |
| 336 | |
| 337 | /////////////////////////////////////////////////////////////////////////// |
| 338 | // (FEC) Forward Error Correction (codec internal) |
| 339 | // |
| 340 | |
| 341 | /////////////////////////////////////////////////////////////////////////// |
| 342 | // int32_t SetCodecFEC() |
| 343 | // Configures codec internal FEC status i.e. on/off. No effects on codecs that |
| 344 | // do not provide internal FEC. |
| 345 | // |
| 346 | // Input: |
| 347 | // -enable_fec : if true FEC will be enabled otherwise the FEC is |
| 348 | // disabled. |
| 349 | // |
| 350 | // Return value: |
| 351 | // -1 if failed, or the codec does not support FEC |
| 352 | // 0 if succeeded. |
| 353 | // |
| 354 | virtual int SetCodecFEC(bool enable_codec_fec) = 0; |
| 355 | |
| 356 | /////////////////////////////////////////////////////////////////////////// |
| 357 | // bool CodecFEC() |
| 358 | // Gets status of codec internal FEC. |
| 359 | // |
| 360 | // Return value: |
| 361 | // true if FEC is enabled, |
| 362 | // false if FEC is disabled. |
| 363 | // |
| 364 | virtual bool CodecFEC() const = 0; |
| 365 | |
| 366 | /////////////////////////////////////////////////////////////////////////// |
| 367 | // int SetPacketLossRate() |
| 368 | // Sets expected packet loss rate for encoding. Some encoders provide packet |
| 369 | // loss gnostic encoding to make stream less sensitive to packet losses, |
| 370 | // through e.g., FEC. No effects on codecs that do not provide such encoding. |
| 371 | // |
| 372 | // Input: |
| 373 | // -packet_loss_rate : expected packet loss rate (0 -- 100 inclusive). |
| 374 | // |
| 375 | // Return value |
| 376 | // -1 if failed to set packet loss rate, |
| 377 | // 0 if succeeded. |
| 378 | // |
minyue | 7e30432 | 2016-10-12 05:00:55 -0700 | [diff] [blame] | 379 | // This is only used in test code that rely on old ACM APIs. |
| 380 | // TODO(minyue): Remove it when possible. |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 381 | virtual int SetPacketLossRate(int packet_loss_rate) = 0; |
| 382 | |
| 383 | /////////////////////////////////////////////////////////////////////////// |
| 384 | // (VAD) Voice Activity Detection |
| 385 | // |
| 386 | |
| 387 | /////////////////////////////////////////////////////////////////////////// |
| 388 | // int32_t SetVAD() |
| 389 | // If DTX is enabled & the codec does not have internal DTX/VAD |
| 390 | // WebRtc VAD will be automatically enabled and |enable_vad| is ignored. |
| 391 | // |
| 392 | // If DTX is disabled but VAD is enabled no DTX packets are send, |
| 393 | // regardless of whether the codec has internal DTX/VAD or not. In this |
| 394 | // case, WebRtc VAD is running to label frames as active/in-active. |
| 395 | // |
| 396 | // NOTE! VAD/DTX is not supported when sending stereo. |
| 397 | // |
| 398 | // Inputs: |
| 399 | // -enable_dtx : if true DTX is enabled, |
| 400 | // otherwise DTX is disabled. |
| 401 | // -enable_vad : if true VAD is enabled, |
| 402 | // otherwise VAD is disabled. |
| 403 | // -vad_mode : determines the aggressiveness of VAD. A more |
| 404 | // aggressive mode results in more frames labeled |
| 405 | // as in-active, c.f. definition of |
| 406 | // ACMVADMode in audio_coding_module_typedefs.h |
| 407 | // for valid values. |
| 408 | // |
| 409 | // Return value: |
| 410 | // -1 if failed to set up VAD/DTX, |
| 411 | // 0 if succeeded. |
| 412 | // |
| 413 | virtual int32_t SetVAD(const bool enable_dtx = true, |
| 414 | const bool enable_vad = false, |
| 415 | const ACMVADMode vad_mode = VADNormal) = 0; |
| 416 | |
| 417 | /////////////////////////////////////////////////////////////////////////// |
| 418 | // int32_t VAD() |
| 419 | // Get VAD status. |
| 420 | // |
| 421 | // Outputs: |
| 422 | // -dtx_enabled : is set to true if DTX is enabled, otherwise |
| 423 | // is set to false. |
| 424 | // -vad_enabled : is set to true if VAD is enabled, otherwise |
| 425 | // is set to false. |
| 426 | // -vad_mode : is set to the current aggressiveness of VAD. |
| 427 | // |
| 428 | // Return value: |
| 429 | // -1 if fails to retrieve the setting of DTX/VAD, |
| 430 | // 0 if succeeded. |
| 431 | // |
| 432 | virtual int32_t VAD(bool* dtx_enabled, bool* vad_enabled, |
| 433 | ACMVADMode* vad_mode) const = 0; |
| 434 | |
| 435 | /////////////////////////////////////////////////////////////////////////// |
| 436 | // int32_t RegisterVADCallback() |
| 437 | // Call this method to register a callback function which is called |
| 438 | // any time that ACM encounters an empty frame. That is a frame which is |
| 439 | // recognized inactive. Depending on the codec WebRtc VAD or internal codec |
| 440 | // VAD is employed to identify a frame as active/inactive. |
| 441 | // |
| 442 | // Input: |
| 443 | // -vad_callback : pointer to a callback function. |
| 444 | // |
| 445 | // Return value: |
| 446 | // -1 if failed to register the callback function. |
| 447 | // 0 if the callback function is registered successfully. |
| 448 | // |
| 449 | virtual int32_t RegisterVADCallback(ACMVADCallback* vad_callback) = 0; |
| 450 | |
| 451 | /////////////////////////////////////////////////////////////////////////// |
| 452 | // Receiver |
| 453 | // |
| 454 | |
| 455 | /////////////////////////////////////////////////////////////////////////// |
| 456 | // int32_t InitializeReceiver() |
| 457 | // Any decoder-related state of ACM will be initialized to the |
| 458 | // same state when ACM is created. This will not interrupt or |
| 459 | // effect encoding functionality of ACM. ACM would lose all the |
| 460 | // decoding-related settings by calling this function. |
| 461 | // For instance, all registered codecs are deleted and have to be |
| 462 | // registered again. |
| 463 | // |
| 464 | // Return value: |
| 465 | // -1 if failed to initialize, |
| 466 | // 0 if succeeded. |
| 467 | // |
| 468 | virtual int32_t InitializeReceiver() = 0; |
| 469 | |
| 470 | /////////////////////////////////////////////////////////////////////////// |
| 471 | // int32_t ReceiveFrequency() |
| 472 | // Get sampling frequency of the last received payload. |
| 473 | // |
| 474 | // Return value: |
| 475 | // non-negative the sampling frequency in Hertz. |
| 476 | // -1 if an error has occurred. |
| 477 | // |
| 478 | virtual int32_t ReceiveFrequency() const = 0; |
| 479 | |
| 480 | /////////////////////////////////////////////////////////////////////////// |
| 481 | // int32_t PlayoutFrequency() |
| 482 | // Get sampling frequency of audio played out. |
| 483 | // |
| 484 | // Return value: |
| 485 | // the sampling frequency in Hertz. |
| 486 | // |
| 487 | virtual int32_t PlayoutFrequency() const = 0; |
| 488 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 489 | // Replace any existing decoders with the given payload type -> decoder map. |
| 490 | virtual void SetReceiveCodecs( |
| 491 | const std::map<int, SdpAudioFormat>& codecs) = 0; |
| 492 | |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 493 | // Registers a decoder for the given payload type. Returns true iff |
| 494 | // successful. |
| 495 | virtual bool RegisterReceiveCodec(int rtp_payload_type, |
| 496 | const SdpAudioFormat& audio_format) = 0; |
| 497 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 498 | /////////////////////////////////////////////////////////////////////////// |
| 499 | // int32_t RegisterReceiveCodec() |
| 500 | // Register possible decoders, can be called multiple times for |
| 501 | // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED. |
| 502 | // |
| 503 | // Input: |
| 504 | // -receive_codec : parameters of the codec to be registered, c.f. |
| 505 | // common_types.h for the definition of |
| 506 | // CodecInst. |
| 507 | // |
| 508 | // Return value: |
| 509 | // -1 if failed to register the codec |
| 510 | // 0 if the codec registered successfully. |
| 511 | // |
| 512 | virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0; |
| 513 | |
kwiberg | 4cdbd57 | 2016-03-30 03:10:05 -0700 | [diff] [blame] | 514 | // Register a decoder; call repeatedly to register multiple decoders. |df| is |
| 515 | // a decoder factory that returns an iSAC decoder; it will be called once if |
| 516 | // the decoder being registered is iSAC. |
| 517 | virtual int RegisterReceiveCodec( |
| 518 | const CodecInst& receive_codec, |
kwiberg | 24c7c12 | 2016-09-28 11:57:10 -0700 | [diff] [blame] | 519 | rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0; |
kwiberg | 4cdbd57 | 2016-03-30 03:10:05 -0700 | [diff] [blame] | 520 | |
henrik.lundin | 4cf61dd | 2015-12-09 06:20:58 -0800 | [diff] [blame] | 521 | // Registers an external decoder. The name is only used to provide information |
| 522 | // back to the caller about the decoder. Hence, the name is arbitrary, and may |
| 523 | // be empty. |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 524 | virtual int RegisterExternalReceiveCodec(int rtp_payload_type, |
| 525 | AudioDecoder* external_decoder, |
| 526 | int sample_rate_hz, |
henrik.lundin | 4cf61dd | 2015-12-09 06:20:58 -0800 | [diff] [blame] | 527 | int num_channels, |
| 528 | const std::string& name) = 0; |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 529 | |
| 530 | /////////////////////////////////////////////////////////////////////////// |
| 531 | // int32_t UnregisterReceiveCodec() |
| 532 | // Unregister the codec currently registered with a specific payload type |
| 533 | // from the list of possible receive codecs. |
| 534 | // |
| 535 | // Input: |
| 536 | // -payload_type : The number representing the payload type to |
| 537 | // unregister. |
| 538 | // |
| 539 | // Output: |
| 540 | // -1 if fails to unregister. |
| 541 | // 0 if the given codec is successfully unregistered. |
| 542 | // |
| 543 | virtual int UnregisterReceiveCodec( |
| 544 | uint8_t payload_type) = 0; |
| 545 | |
| 546 | /////////////////////////////////////////////////////////////////////////// |
| 547 | // int32_t ReceiveCodec() |
| 548 | // Get the codec associated with last received payload. |
| 549 | // |
| 550 | // Output: |
| 551 | // -curr_receive_codec : parameters of the codec associated with the last |
| 552 | // received payload, c.f. common_types.h for |
| 553 | // the definition of CodecInst. |
| 554 | // |
| 555 | // Return value: |
| 556 | // -1 if failed to retrieve the codec, |
| 557 | // 0 if the codec is successfully retrieved. |
| 558 | // |
| 559 | virtual int32_t ReceiveCodec(CodecInst* curr_receive_codec) const = 0; |
| 560 | |
| 561 | /////////////////////////////////////////////////////////////////////////// |
ossu | e280cde | 2016-10-12 11:04:10 -0700 | [diff] [blame] | 562 | // rtc::Optional<SdpAudioFormat> ReceiveFormat() |
| 563 | // Get the format associated with last received payload. |
| 564 | // |
| 565 | // Return value: |
| 566 | // An SdpAudioFormat describing the format associated with the last |
| 567 | // received payload. |
| 568 | // An empty Optional if no payload has yet been received. |
| 569 | // |
| 570 | virtual rtc::Optional<SdpAudioFormat> ReceiveFormat() const = 0; |
| 571 | |
| 572 | /////////////////////////////////////////////////////////////////////////// |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 573 | // int32_t IncomingPacket() |
| 574 | // Call this function to insert a parsed RTP packet into ACM. |
| 575 | // |
| 576 | // Inputs: |
| 577 | // -incoming_payload : received payload. |
| 578 | // -payload_len_bytes : the length of payload in bytes. |
| 579 | // -rtp_info : the relevant information retrieved from RTP |
| 580 | // header. |
| 581 | // |
| 582 | // Return value: |
| 583 | // -1 if failed to push in the payload |
| 584 | // 0 if payload is successfully pushed in. |
| 585 | // |
| 586 | virtual int32_t IncomingPacket(const uint8_t* incoming_payload, |
| 587 | const size_t payload_len_bytes, |
| 588 | const WebRtcRTPHeader& rtp_info) = 0; |
| 589 | |
| 590 | /////////////////////////////////////////////////////////////////////////// |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 591 | // int SetMinimumPlayoutDelay() |
| 592 | // Set a minimum for the playout delay, used for lip-sync. NetEq maintains |
| 593 | // such a delay unless channel condition yields to a higher delay. |
| 594 | // |
| 595 | // Input: |
| 596 | // -time_ms : minimum delay in milliseconds. |
| 597 | // |
| 598 | // Return value: |
| 599 | // -1 if failed to set the delay, |
| 600 | // 0 if the minimum delay is set. |
| 601 | // |
| 602 | virtual int SetMinimumPlayoutDelay(int time_ms) = 0; |
| 603 | |
| 604 | /////////////////////////////////////////////////////////////////////////// |
| 605 | // int SetMaximumPlayoutDelay() |
| 606 | // Set a maximum for the playout delay |
| 607 | // |
| 608 | // Input: |
| 609 | // -time_ms : maximum delay in milliseconds. |
| 610 | // |
| 611 | // Return value: |
| 612 | // -1 if failed to set the delay, |
| 613 | // 0 if the maximum delay is set. |
| 614 | // |
| 615 | virtual int SetMaximumPlayoutDelay(int time_ms) = 0; |
| 616 | |
solenberg | 08b19df | 2017-02-15 00:42:31 -0800 | [diff] [blame] | 617 | // TODO(kwiberg): Consider if this is needed anymore, now that voe::Channel |
| 618 | // doesn't use it. |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 619 | // The shortest latency, in milliseconds, required by jitter buffer. This |
| 620 | // is computed based on inter-arrival times and playout mode of NetEq. The |
| 621 | // actual delay is the maximum of least-required-delay and the minimum-delay |
| 622 | // specified by SetMinumumPlayoutDelay() API. |
| 623 | // |
| 624 | virtual int LeastRequiredDelayMs() const = 0; |
| 625 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 626 | // int32_t PlayoutTimestamp() |
| 627 | // The send timestamp of an RTP packet is associated with the decoded |
| 628 | // audio of the packet in question. This function returns the timestamp of |
| 629 | // the latest audio obtained by calling PlayoutData10ms(). |
| 630 | // |
| 631 | // Input: |
| 632 | // -timestamp : a reference to a uint32_t to receive the |
| 633 | // timestamp. |
| 634 | // Return value: |
| 635 | // 0 if the output is a correct timestamp. |
| 636 | // -1 if failed to output the correct timestamp. |
| 637 | // |
henrik.lundin | 9a410dd | 2016-04-06 01:39:22 -0700 | [diff] [blame] | 638 | RTC_DEPRECATED virtual int32_t PlayoutTimestamp(uint32_t* timestamp) = 0; |
| 639 | |
| 640 | /////////////////////////////////////////////////////////////////////////// |
| 641 | // int32_t PlayoutTimestamp() |
| 642 | // The send timestamp of an RTP packet is associated with the decoded |
| 643 | // audio of the packet in question. This function returns the timestamp of |
| 644 | // the latest audio obtained by calling PlayoutData10ms(), or empty if no |
| 645 | // valid timestamp is available. |
| 646 | // |
| 647 | virtual rtc::Optional<uint32_t> PlayoutTimestamp() = 0; |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 648 | |
| 649 | /////////////////////////////////////////////////////////////////////////// |
henrik.lundin | b3f1c5d | 2016-08-22 15:39:53 -0700 | [diff] [blame] | 650 | // int FilteredCurrentDelayMs() |
| 651 | // Returns the current total delay from NetEq (packet buffer and sync buffer) |
| 652 | // in ms, with smoothing applied to even out short-time fluctuations due to |
| 653 | // jitter. The packet buffer part of the delay is not updated during DTX/CNG |
| 654 | // periods. |
| 655 | // |
| 656 | virtual int FilteredCurrentDelayMs() const = 0; |
| 657 | |
| 658 | /////////////////////////////////////////////////////////////////////////// |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 659 | // int32_t PlayoutData10Ms( |
| 660 | // Get 10 milliseconds of raw audio data for playout, at the given sampling |
| 661 | // frequency. ACM will perform a resampling if required. |
| 662 | // |
| 663 | // Input: |
| 664 | // -desired_freq_hz : the desired sampling frequency, in Hertz, of the |
| 665 | // output audio. If set to -1, the function returns |
| 666 | // the audio at the current sampling frequency. |
| 667 | // |
| 668 | // Output: |
| 669 | // -audio_frame : output audio frame which contains raw audio data |
| 670 | // and other relevant parameters, c.f. |
| 671 | // module_common_types.h for the definition of |
| 672 | // AudioFrame. |
henrik.lundin | 834a6ea | 2016-05-13 03:45:24 -0700 | [diff] [blame] | 673 | // -muted : if true, the sample data in audio_frame is not |
| 674 | // populated, and must be interpreted as all zero. |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 675 | // |
| 676 | // Return value: |
| 677 | // -1 if the function fails, |
| 678 | // 0 if the function succeeds. |
| 679 | // |
| 680 | virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz, |
henrik.lundin | 834a6ea | 2016-05-13 03:45:24 -0700 | [diff] [blame] | 681 | AudioFrame* audio_frame, |
| 682 | bool* muted) = 0; |
| 683 | |
| 684 | ///////////////////////////////////////////////////////////////////////////// |
| 685 | // Same as above, but without the muted parameter. This methods should not be |
| 686 | // used if enable_fast_accelerate was set to true in NetEq::Config. |
| 687 | // TODO(henrik.lundin) Remove this method when downstream dependencies are |
| 688 | // ready. |
| 689 | virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz, |
| 690 | AudioFrame* audio_frame) = 0; |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 691 | |
| 692 | /////////////////////////////////////////////////////////////////////////// |
| 693 | // Codec specific |
| 694 | // |
| 695 | |
| 696 | /////////////////////////////////////////////////////////////////////////// |
| 697 | // int SetOpusApplication() |
| 698 | // Sets the intended application if current send codec is Opus. Opus uses this |
| 699 | // to optimize the encoding for applications like VOIP and music. Currently, |
| 700 | // two modes are supported: kVoip and kAudio. |
| 701 | // |
| 702 | // Input: |
| 703 | // - application : intended application. |
| 704 | // |
| 705 | // Return value: |
| 706 | // -1 if current send codec is not Opus or error occurred in setting the |
| 707 | // Opus application mode. |
| 708 | // 0 if the Opus application mode is successfully set. |
| 709 | // |
| 710 | virtual int SetOpusApplication(OpusApplicationMode application) = 0; |
| 711 | |
| 712 | /////////////////////////////////////////////////////////////////////////// |
| 713 | // int SetOpusMaxPlaybackRate() |
| 714 | // If current send codec is Opus, informs it about maximum playback rate the |
| 715 | // receiver will render. Opus can use this information to optimize the bit |
| 716 | // rate and increase the computation efficiency. |
| 717 | // |
| 718 | // Input: |
| 719 | // -frequency_hz : maximum playback rate in Hz. |
| 720 | // |
| 721 | // Return value: |
| 722 | // -1 if current send codec is not Opus or |
| 723 | // error occurred in setting the maximum playback rate, |
| 724 | // 0 if maximum bandwidth is set successfully. |
| 725 | // |
| 726 | virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0; |
| 727 | |
| 728 | /////////////////////////////////////////////////////////////////////////// |
| 729 | // EnableOpusDtx() |
| 730 | // Enable the DTX, if current send codec is Opus. |
| 731 | // |
| 732 | // Return value: |
| 733 | // -1 if current send codec is not Opus or error occurred in enabling the |
| 734 | // Opus DTX. |
| 735 | // 0 if Opus DTX is enabled successfully. |
| 736 | // |
| 737 | virtual int EnableOpusDtx() = 0; |
| 738 | |
| 739 | /////////////////////////////////////////////////////////////////////////// |
| 740 | // int DisableOpusDtx() |
| 741 | // If current send codec is Opus, disables its internal DTX. |
| 742 | // |
| 743 | // Return value: |
| 744 | // -1 if current send codec is not Opus or error occurred in disabling DTX. |
| 745 | // 0 if Opus DTX is disabled successfully. |
| 746 | // |
| 747 | virtual int DisableOpusDtx() = 0; |
| 748 | |
| 749 | /////////////////////////////////////////////////////////////////////////// |
| 750 | // statistics |
| 751 | // |
| 752 | |
| 753 | /////////////////////////////////////////////////////////////////////////// |
| 754 | // int32_t GetNetworkStatistics() |
| 755 | // Get network statistics. Note that the internal statistics of NetEq are |
| 756 | // reset by this call. |
| 757 | // |
| 758 | // Input: |
| 759 | // -network_statistics : a structure that contains network statistics. |
| 760 | // |
| 761 | // Return value: |
| 762 | // -1 if failed to set the network statistics, |
| 763 | // 0 if statistics are set successfully. |
| 764 | // |
| 765 | virtual int32_t GetNetworkStatistics( |
| 766 | NetworkStatistics* network_statistics) = 0; |
| 767 | |
| 768 | // |
| 769 | // Enable NACK and set the maximum size of the NACK list. If NACK is already |
| 770 | // enable then the maximum NACK list size is modified accordingly. |
| 771 | // |
| 772 | // If the sequence number of last received packet is N, the sequence numbers |
| 773 | // of NACK list are in the range of [N - |max_nack_list_size|, N). |
| 774 | // |
| 775 | // |max_nack_list_size| should be positive (none zero) and less than or |
| 776 | // equal to |Nack::kNackListSizeLimit|. Otherwise, No change is applied and -1 |
| 777 | // is returned. 0 is returned at success. |
| 778 | // |
| 779 | virtual int EnableNack(size_t max_nack_list_size) = 0; |
| 780 | |
| 781 | // Disable NACK. |
| 782 | virtual void DisableNack() = 0; |
| 783 | |
| 784 | // |
| 785 | // Get a list of packets to be retransmitted. |round_trip_time_ms| is an |
| 786 | // estimate of the round-trip-time (in milliseconds). Missing packets which |
| 787 | // will be playout in a shorter time than the round-trip-time (with respect |
| 788 | // to the time this API is called) will not be included in the list. |
| 789 | // |
| 790 | // Negative |round_trip_time_ms| results is an error message and empty list |
| 791 | // is returned. |
| 792 | // |
| 793 | virtual std::vector<uint16_t> GetNackList( |
| 794 | int64_t round_trip_time_ms) const = 0; |
| 795 | |
| 796 | virtual void GetDecodingCallStatistics( |
| 797 | AudioDecodingCallStats* call_stats) const = 0; |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 798 | |
| 799 | virtual ANAStats GetANAStats() const = 0; |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 800 | }; |
| 801 | |
| 802 | } // namespace webrtc |
| 803 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 804 | #endif // MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |