Make the echo detector injectable.
This adds a generic interface for an echo detector, and makes it possible to inject one into the audio processing module.
Bug: webrtc:8732
Change-Id: I30d97aeb829307b2ae9c4dbeb9a3e15ab7ec0912
Reviewed-on: https://webrtc-review.googlesource.com/38900
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21588}
diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h
index 60bf0c7..8951b8c 100644
--- a/modules/audio_processing/include/audio_processing.h
+++ b/modules/audio_processing/include/audio_processing.h
@@ -49,6 +49,7 @@
class EchoCancellation;
class EchoControlMobile;
class EchoControlFactory;
+class EchoDetector;
class GainControl;
class HighPassFilter;
class LevelEstimator;
@@ -665,6 +666,9 @@
// The AudioProcessingBuilder takes ownership of the nonlinear beamformer.
AudioProcessingBuilder& SetNonlinearBeamformer(
std::unique_ptr<NonlinearBeamformer> nonlinear_beamformer);
+ // The AudioProcessingBuilder takes ownership of the echo_detector.
+ AudioProcessingBuilder& SetEchoDetector(
+ std::unique_ptr<EchoDetector> echo_detector);
// This creates an APM instance using the previously set components. Calling
// the Create function resets the AudioProcessingBuilder to its initial state.
AudioProcessing* Create();
@@ -675,6 +679,7 @@
std::unique_ptr<CustomProcessing> capture_post_processing_;
std::unique_ptr<CustomProcessing> render_pre_processing_;
std::unique_ptr<NonlinearBeamformer> nonlinear_beamformer_;
+ std::unique_ptr<EchoDetector> echo_detector_;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioProcessingBuilder);
};
@@ -1147,6 +1152,34 @@
virtual ~CustomProcessing() {}
};
+// Interface for an echo detector submodule.
+class EchoDetector {
+ public:
+ // (Re-)Initializes the submodule.
+ virtual void Initialize(int sample_rate_hz, int num_channels) = 0;
+
+ // Analysis (not changing) of the render signal.
+ virtual void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) = 0;
+
+ // Analysis (not changing) of the capture signal.
+ virtual void AnalyzeCaptureAudio(
+ rtc::ArrayView<const float> capture_audio) = 0;
+
+ // Pack an AudioBuffer into a vector<float>.
+ static void PackRenderAudioBuffer(AudioBuffer* audio,
+ std::vector<float>* packed_buffer);
+
+ struct Metrics {
+ double echo_likelihood;
+ double echo_likelihood_recent_max;
+ };
+
+ // Collect current metrics from the echo detector.
+ virtual Metrics GetMetrics() const = 0;
+
+ virtual ~EchoDetector() {}
+};
+
// The voice activity detection (VAD) component analyzes the stream to
// determine if voice is present. A facility is also provided to pass in an
// external VAD decision.