echo_control.h (2907B)
1 /* 2 * Copyright (c) 2018 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 11 #ifndef API_AUDIO_ECHO_CONTROL_H_ 12 #define API_AUDIO_ECHO_CONTROL_H_ 13 14 #include <memory> 15 16 #include "absl/base/nullability.h" 17 #include "api/audio/neural_residual_echo_estimator.h" 18 #include "api/environment/environment.h" 19 20 namespace webrtc { 21 22 class AudioBuffer; 23 24 // Interface for an acoustic echo cancellation (AEC) submodule. 25 class EchoControl { 26 public: 27 // Analysis (not changing) of the render signal. 28 virtual void AnalyzeRender(AudioBuffer* render) = 0; 29 30 // Analysis (not changing) of the capture signal. 31 virtual void AnalyzeCapture(AudioBuffer* capture) = 0; 32 33 // Processes the capture signal in order to remove the echo. 34 virtual void ProcessCapture(AudioBuffer* capture, bool level_change) = 0; 35 36 // As above, but also returns the linear filter output. 37 virtual void ProcessCapture(AudioBuffer* capture, 38 AudioBuffer* linear_output, 39 bool level_change) = 0; 40 41 struct Metrics { 42 double echo_return_loss; 43 double echo_return_loss_enhancement; 44 int delay_ms; 45 }; 46 47 // Collect current metrics from the echo controller. 48 virtual Metrics GetMetrics() const = 0; 49 50 // Provides an optional external estimate of the audio buffer delay. 51 virtual void SetAudioBufferDelay(int delay_ms) = 0; 52 53 // Specifies whether the capture output will be used. The purpose of this is 54 // to allow the echo controller to deactivate some of the processing when the 55 // resulting output is anyway not used, for instance when the endpoint is 56 // muted. 57 // TODO(b/177830919): Make pure virtual. 58 virtual void SetCaptureOutputUsage(bool /* capture_output_used */) {} 59 60 // Returns wheter the signal is altered. 61 virtual bool ActiveProcessing() const = 0; 62 63 virtual ~EchoControl() {} 64 }; 65 66 // Interface for a factory that creates EchoControllers. 67 class EchoControlFactory { 68 public: 69 virtual ~EchoControlFactory() = default; 70 71 virtual absl_nonnull std::unique_ptr<EchoControl> Create( 72 const Environment& env, 73 int sample_rate_hz, 74 int num_render_channels, 75 int num_capture_channels) = 0; 76 77 virtual absl_nonnull std::unique_ptr<EchoControl> Create( 78 const Environment& env, 79 int sample_rate_hz, 80 int num_render_channels, 81 int num_capture_channels, 82 NeuralResidualEchoEstimator* neural_residual_echo_estimator) { 83 return Create(env, sample_rate_hz, num_render_channels, 84 num_capture_channels); 85 } 86 }; 87 88 } // namespace webrtc 89 90 #endif // API_AUDIO_ECHO_CONTROL_H_