1 /*
2  *  Copyright (c) 2016 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 MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_H_
13 
14 #include <stddef.h>
15 
16 #include <memory>
17 #include <vector>
18 
19 #include "api/audio/echo_canceller3_config.h"
20 #include "api/audio/echo_control.h"
21 #include "modules/audio_processing/aec3/echo_remover.h"
22 #include "modules/audio_processing/aec3/render_delay_buffer.h"
23 #include "modules/audio_processing/aec3/render_delay_controller.h"
24 
25 namespace webrtc {
26 
27 // Class for performing echo cancellation on 64 sample blocks of audio data.
28 class BlockProcessor {
29  public:
30   static BlockProcessor* Create(const EchoCanceller3Config& config,
31                                 int sample_rate_hz,
32                                 size_t num_render_channels,
33                                 size_t num_capture_channels);
34   // Only used for testing purposes.
35   static BlockProcessor* Create(
36       const EchoCanceller3Config& config,
37       int sample_rate_hz,
38       size_t num_render_channels,
39       size_t num_capture_channels,
40       std::unique_ptr<RenderDelayBuffer> render_buffer);
41   static BlockProcessor* Create(
42       const EchoCanceller3Config& config,
43       int sample_rate_hz,
44       size_t num_render_channels,
45       size_t num_capture_channels,
46       std::unique_ptr<RenderDelayBuffer> render_buffer,
47       std::unique_ptr<RenderDelayController> delay_controller,
48       std::unique_ptr<EchoRemover> echo_remover);
49 
50   virtual ~BlockProcessor() = default;
51 
52   // Get current metrics.
53   virtual void GetMetrics(EchoControl::Metrics* metrics) const = 0;
54 
55   // Provides an optional external estimate of the audio buffer delay.
56   virtual void SetAudioBufferDelay(int delay_ms) = 0;
57 
58   // Processes a block of capture data.
59   virtual void ProcessCapture(
60       bool echo_path_gain_change,
61       bool capture_signal_saturation,
62       std::vector<std::vector<std::vector<float>>>* linear_output,
63       std::vector<std::vector<std::vector<float>>>* capture_block) = 0;
64 
65   // Buffers a block of render data supplied by a FrameBlocker object.
66   virtual void BufferRender(
67       const std::vector<std::vector<std::vector<float>>>& render_block) = 0;
68 
69   // Reports whether echo leakage has been detected in the echo canceller
70   // output.
71   virtual void UpdateEchoLeakageStatus(bool leakage_detected) = 0;
72 };
73 
74 }  // namespace webrtc
75 
76 #endif  // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_H_
77