| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ |
| 12 |
#define MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ |
| 13 |
|
| 14 |
#include <stddef.h> |
| 15 |
|
| 16 |
#include <memory> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include "api/array_view.h" |
| 20 |
#include "api/audio/echo_canceller3_config.h" |
| 21 |
#include "api/audio/echo_control.h" |
| 22 |
#include "modules/audio_processing/aec3/api_call_jitter_metrics.h" |
| 23 |
#include "modules/audio_processing/aec3/block_delay_buffer.h" |
| 24 |
#include "modules/audio_processing/aec3/block_framer.h" |
| 25 |
#include "modules/audio_processing/aec3/block_processor.h" |
| 26 |
#include "modules/audio_processing/aec3/frame_blocker.h" |
| 27 |
#include "modules/audio_processing/audio_buffer.h" |
| 28 |
#include "modules/audio_processing/logging/apm_data_dumper.h" |
| 29 |
#include "rtc_base/checks.h" |
| 30 |
#include "rtc_base/race_checker.h" |
| 31 |
#include "rtc_base/swap_queue.h" |
| 32 |
#include "rtc_base/thread_annotations.h" |
| 33 |
|
| 34 |
namespace webrtc { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
EchoCanceller3Config AdjustConfig(const EchoCanceller3Config& config); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
class Aec3RenderQueueItemVerifier { |
| 44 |
public: |
| 45 |
Aec3RenderQueueItemVerifier(size_t num_bands, |
| 46 |
size_t num_channels, |
| 47 |
size_t frame_length) |
| 48 |
: num_bands_(num_bands), |
| 49 |
num_channels_(num_channels), |
| 50 |
frame_length_(frame_length) {} |
| 51 |
|
| 52 |
bool operator()(const std::vector<std::vector<std::vector<float>>>& v) const { |
| 53 |
if (v.size() != num_bands_) { |
| 54 |
return false; |
| 55 |
} |
| 56 |
for (const auto& band : v) { |
| 57 |
if (band.size() != num_channels_) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
for (const auto& channel : band) { |
| 61 |
if (channel.size() != frame_length_) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
private: |
| 70 |
const size_t num_bands_; |
| 71 |
const size_t num_channels_; |
| 72 |
const size_t frame_length_; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
class EchoCanceller3 : public EchoControl { |
| 86 |
public: |
| 87 |
|
| 88 |
EchoCanceller3(const EchoCanceller3Config& config, |
| 89 |
int sample_rate_hz, |
| 90 |
size_t num_render_channels, |
| 91 |
size_t num_capture_channels); |
| 92 |
|
| 93 |
EchoCanceller3(const EchoCanceller3Config& config, |
| 94 |
int sample_rate_hz, |
| 95 |
size_t num_render_channels, |
| 96 |
size_t num_capture_channels, |
| 97 |
std::unique_ptr<BlockProcessor> block_processor); |
| 98 |
~EchoCanceller3() override; |
| 99 |
EchoCanceller3(const EchoCanceller3&) = delete; |
| 100 |
EchoCanceller3& operator=(const EchoCanceller3&) = delete; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
void AnalyzeRender(AudioBuffer* render) override { AnalyzeRender(*render); } |
| 105 |
|
| 106 |
void AnalyzeCapture(AudioBuffer* capture) override { |
| 107 |
AnalyzeCapture(*capture); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
void ProcessCapture(AudioBuffer* capture, bool level_change) override; |
| 112 |
|
| 113 |
void ProcessCapture(AudioBuffer* capture, |
| 114 |
AudioBuffer* linear_output, |
| 115 |
bool level_change) override; |
| 116 |
|
| 117 |
Metrics GetMetrics() const override; |
| 118 |
|
| 119 |
void SetAudioBufferDelay(int delay_ms) override; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
void SetCaptureOutputUsage(bool capture_output_used) override; |
| 126 |
|
| 127 |
bool ActiveProcessing() const override; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
void UpdateEchoLeakageStatus(bool leakage_detected) { |
| 134 |
RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
| 135 |
block_processor_->UpdateEchoLeakageStatus(leakage_detected); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
static EchoCanceller3Config CreateDefaultConfig(size_t num_render_channels, |
| 141 |
size_t num_capture_channels); |
| 142 |
|
| 143 |
private: |
| 144 |
class RenderWriter; |
| 145 |
|
| 146 |
|
| 147 |
void EmptyRenderQueue(); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
void AnalyzeRender(const AudioBuffer& render); |
| 152 |
|
| 153 |
void AnalyzeCapture(const AudioBuffer& capture); |
| 154 |
|
| 155 |
rtc::RaceChecker capture_race_checker_; |
| 156 |
rtc::RaceChecker render_race_checker_; |
| 157 |
|
| 158 |
|
| 159 |
std::unique_ptr<RenderWriter> render_writer_ |
| 160 |
RTC_GUARDED_BY(render_race_checker_); |
| 161 |
|
| 162 |
|
| 163 |
static int instance_count_; |
| 164 |
std::unique_ptr<ApmDataDumper> data_dumper_; |
| 165 |
const EchoCanceller3Config config_; |
| 166 |
const int sample_rate_hz_; |
| 167 |
const int num_bands_; |
| 168 |
const size_t num_render_channels_; |
| 169 |
const size_t num_capture_channels_; |
| 170 |
std::unique_ptr<BlockFramer> linear_output_framer_ |
| 171 |
RTC_GUARDED_BY(capture_race_checker_); |
| 172 |
BlockFramer output_framer_ RTC_GUARDED_BY(capture_race_checker_); |
| 173 |
FrameBlocker capture_blocker_ RTC_GUARDED_BY(capture_race_checker_); |
| 174 |
FrameBlocker render_blocker_ RTC_GUARDED_BY(capture_race_checker_); |
| 175 |
SwapQueue<std::vector<std::vector<std::vector<float>>>, |
| 176 |
Aec3RenderQueueItemVerifier> |
| 177 |
render_transfer_queue_; |
| 178 |
std::unique_ptr<BlockProcessor> block_processor_ |
| 179 |
RTC_GUARDED_BY(capture_race_checker_); |
| 180 |
std::vector<std::vector<std::vector<float>>> render_queue_output_frame_ |
| 181 |
RTC_GUARDED_BY(capture_race_checker_); |
| 182 |
bool saturated_microphone_signal_ RTC_GUARDED_BY(capture_race_checker_) = |
| 183 |
false; |
| 184 |
std::vector<std::vector<std::vector<float>>> render_block_ |
| 185 |
RTC_GUARDED_BY(capture_race_checker_); |
| 186 |
std::unique_ptr<std::vector<std::vector<std::vector<float>>>> |
| 187 |
linear_output_block_ RTC_GUARDED_BY(capture_race_checker_); |
| 188 |
std::vector<std::vector<std::vector<float>>> capture_block_ |
| 189 |
RTC_GUARDED_BY(capture_race_checker_); |
| 190 |
std::vector<std::vector<rtc::ArrayView<float>>> render_sub_frame_view_ |
| 191 |
RTC_GUARDED_BY(capture_race_checker_); |
| 192 |
std::vector<std::vector<rtc::ArrayView<float>>> linear_output_sub_frame_view_ |
| 193 |
RTC_GUARDED_BY(capture_race_checker_); |
| 194 |
std::vector<std::vector<rtc::ArrayView<float>>> capture_sub_frame_view_ |
| 195 |
RTC_GUARDED_BY(capture_race_checker_); |
| 196 |
std::unique_ptr<BlockDelayBuffer> block_delay_buffer_ |
| 197 |
RTC_GUARDED_BY(capture_race_checker_); |
| 198 |
ApiCallJitterMetrics api_call_metrics_ RTC_GUARDED_BY(capture_race_checker_); |
| 199 |
}; |
| 200 |
} |
| 201 |
|
| 202 |
#endif |