niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 13 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <string.h> |
| 15 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/audio_processing/aec/aec_core.h" |
Henrik Kjellander | 9b72af9 | 2015-11-11 20:16:11 +0100 | [diff] [blame] | 17 | #include "webrtc/modules/audio_processing/aec/echo_cancellation.h" |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/audio_buffer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | namespace { |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 23 | int16_t MapSetting(EchoCancellation::SuppressionLevel level) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | switch (level) { |
| 25 | case EchoCancellation::kLowSuppression: |
| 26 | return kAecNlpConservative; |
| 27 | case EchoCancellation::kModerateSuppression: |
| 28 | return kAecNlpModerate; |
| 29 | case EchoCancellation::kHighSuppression: |
| 30 | return kAecNlpAggressive; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | } |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 32 | assert(false); |
mflodman@webrtc.org | 657b2a4 | 2012-02-06 11:06:01 +0000 | [diff] [blame] | 33 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
andrew@webrtc.org | 648af74 | 2012-02-08 01:57:29 +0000 | [diff] [blame] | 36 | AudioProcessing::Error MapError(int err) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | switch (err) { |
| 38 | case AEC_UNSUPPORTED_FUNCTION_ERROR: |
| 39 | return AudioProcessing::kUnsupportedFunctionError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | case AEC_BAD_PARAMETER_ERROR: |
| 41 | return AudioProcessing::kBadParameterError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | case AEC_BAD_PARAMETER_WARNING: |
| 43 | return AudioProcessing::kBadStreamParameterWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | default: |
| 45 | // AEC_UNSPECIFIED_ERROR |
| 46 | // AEC_UNINITIALIZED_ERROR |
| 47 | // AEC_NULL_POINTER_ERROR |
| 48 | return AudioProcessing::kUnspecifiedError; |
| 49 | } |
| 50 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
peah | 2446e5a | 2015-11-18 06:11:13 -0800 | [diff] [blame] | 52 | // Maximum length that a frame of samples can have. |
| 53 | static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160; |
| 54 | // Maximum number of frames to buffer in the render queue. |
| 55 | // TODO(peah): Decrease this once we properly handle hugely unbalanced |
| 56 | // reverse and forward call numbers. |
| 57 | static const size_t kMaxNumFramesToBuffer = 100; |
| 58 | } // namespace |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 59 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 60 | struct EchoCancellationImpl::StreamProperties { |
| 61 | StreamProperties() = delete; |
| 62 | StreamProperties(int sample_rate_hz, |
| 63 | size_t num_reverse_channels, |
| 64 | size_t num_output_channels, |
| 65 | size_t num_proc_channels) |
| 66 | : sample_rate_hz(sample_rate_hz), |
| 67 | num_reverse_channels(num_reverse_channels), |
| 68 | num_output_channels(num_output_channels), |
| 69 | num_proc_channels(num_proc_channels) {} |
| 70 | |
| 71 | const int sample_rate_hz; |
| 72 | const size_t num_reverse_channels; |
| 73 | const size_t num_output_channels; |
| 74 | const size_t num_proc_channels; |
| 75 | }; |
| 76 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 77 | class EchoCancellationImpl::Canceller { |
| 78 | public: |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 79 | Canceller() { |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 80 | state_ = WebRtcAec_Create(); |
| 81 | RTC_DCHECK(state_); |
| 82 | } |
| 83 | |
| 84 | ~Canceller() { |
| 85 | RTC_CHECK(state_); |
| 86 | WebRtcAec_Free(state_); |
| 87 | } |
| 88 | |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 89 | void* state() { return state_; } |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 90 | |
| 91 | void Initialize(int sample_rate_hz) { |
| 92 | // TODO(ajm): Drift compensation is disabled in practice. If restored, it |
| 93 | // should be managed internally and not depend on the hardware sample rate. |
| 94 | // For now, just hardcode a 48 kHz value. |
| 95 | const int error = WebRtcAec_Init(state_, sample_rate_hz, 48000); |
| 96 | RTC_DCHECK_EQ(0, error); |
| 97 | } |
| 98 | |
| 99 | private: |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 100 | void* state_; |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 103 | EchoCancellationImpl::EchoCancellationImpl(rtc::CriticalSection* crit_render, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 104 | rtc::CriticalSection* crit_capture) |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 105 | : crit_render_(crit_render), |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 106 | crit_capture_(crit_capture), |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 107 | drift_compensation_enabled_(false), |
| 108 | metrics_enabled_(false), |
| 109 | suppression_level_(kModerateSuppression), |
| 110 | stream_drift_samples_(0), |
| 111 | was_stream_drift_set_(false), |
| 112 | stream_has_echo_(false), |
| 113 | delay_logging_enabled_(false), |
| 114 | extended_filter_enabled_(false), |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 115 | delay_agnostic_enabled_(false), |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 116 | aec3_enabled_(false), |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 117 | render_queue_element_max_size_(0) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 118 | RTC_DCHECK(crit_render); |
| 119 | RTC_DCHECK(crit_capture); |
| 120 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
| 122 | EchoCancellationImpl::~EchoCancellationImpl() {} |
| 123 | |
| 124 | int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 125 | rtc::CritScope cs_render(crit_render_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 126 | if (!enabled_) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 127 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | } |
| 129 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 130 | RTC_DCHECK(stream_properties_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 131 | RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 132 | RTC_DCHECK_EQ(audio->num_channels(), |
| 133 | stream_properties_->num_reverse_channels); |
| 134 | RTC_DCHECK_GE(cancellers_.size(), stream_properties_->num_output_channels * |
| 135 | audio->num_channels()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 137 | int err = AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
| 139 | // The ordering convention must be followed to pass to the correct AEC. |
| 140 | size_t handle_index = 0; |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 141 | render_queue_buffer_.clear(); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 142 | for (size_t i = 0; i < stream_properties_->num_output_channels; i++) { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 143 | for (size_t j = 0; j < audio->num_channels(); j++) { |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 144 | // Retrieve any error code produced by the buffering of the farend |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 145 | // signal. |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 146 | err = WebRtcAec_GetBufferFarendError( |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 147 | cancellers_[handle_index++]->state(), |
| 148 | audio->split_bands_const_f(j)[kBand0To8kHz], |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 149 | audio->num_frames_per_band()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 151 | if (err != AudioProcessing::kNoError) { |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 152 | return MapError(err); // TODO(ajm): warning possible? |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | } |
| 154 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 155 | // Buffer the samples in the render queue. |
| 156 | render_queue_buffer_.insert(render_queue_buffer_.end(), |
| 157 | audio->split_bands_const_f(j)[kBand0To8kHz], |
| 158 | (audio->split_bands_const_f(j)[kBand0To8kHz] + |
| 159 | audio->num_frames_per_band())); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 163 | // Insert the samples into the queue. |
| 164 | if (!render_signal_queue_->Insert(&render_queue_buffer_)) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 165 | // The data queue is full and needs to be emptied. |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 166 | ReadQueuedRenderData(); |
| 167 | |
| 168 | // Retry the insert (should always work). |
| 169 | RTC_DCHECK_EQ(render_signal_queue_->Insert(&render_queue_buffer_), true); |
| 170 | } |
| 171 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 172 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | } |
| 174 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 175 | // Read chunks of data that were received and queued on the render side from |
| 176 | // a queue. All the data chunks are buffered into the farend signal of the AEC. |
| 177 | void EchoCancellationImpl::ReadQueuedRenderData() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 178 | rtc::CritScope cs_capture(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 179 | if (!enabled_) { |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 180 | return; |
| 181 | } |
| 182 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 183 | RTC_DCHECK(stream_properties_); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 184 | while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
| 185 | size_t handle_index = 0; |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 186 | size_t buffer_index = 0; |
| 187 | const size_t num_frames_per_band = |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 188 | capture_queue_buffer_.size() / |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 189 | (stream_properties_->num_output_channels * |
| 190 | stream_properties_->num_reverse_channels); |
| 191 | for (size_t i = 0; i < stream_properties_->num_output_channels; i++) { |
| 192 | for (size_t j = 0; j < stream_properties_->num_reverse_channels; j++) { |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 193 | WebRtcAec_BufferFarend(cancellers_[handle_index++]->state(), |
| 194 | &capture_queue_buffer_[buffer_index], |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 195 | num_frames_per_band); |
| 196 | |
| 197 | buffer_index += num_frames_per_band; |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 203 | int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio, |
| 204 | int stream_delay_ms) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 205 | rtc::CritScope cs_capture(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 206 | if (!enabled_) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 207 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | } |
| 209 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | if (drift_compensation_enabled_ && !was_stream_drift_set_) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 211 | return AudioProcessing::kStreamParameterNotSetError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | } |
| 213 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 214 | RTC_DCHECK(stream_properties_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 215 | RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 216 | RTC_DCHECK_EQ(audio->num_channels(), stream_properties_->num_proc_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 218 | int err = AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 219 | |
| 220 | // The ordering convention must be followed to pass to the correct AEC. |
| 221 | size_t handle_index = 0; |
| 222 | stream_has_echo_ = false; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 223 | for (size_t i = 0; i < audio->num_channels(); i++) { |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 224 | for (size_t j = 0; j < stream_properties_->num_reverse_channels; j++) { |
| 225 | err = WebRtcAec_Process( |
| 226 | cancellers_[handle_index]->state(), audio->split_bands_const_f(i), |
| 227 | audio->num_bands(), audio->split_bands_f(i), |
| 228 | audio->num_frames_per_band(), stream_delay_ms, stream_drift_samples_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 230 | if (err != AudioProcessing::kNoError) { |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 231 | err = MapError(err); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | // TODO(ajm): Figure out how to return warnings properly. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 233 | if (err != AudioProcessing::kBadStreamParameterWarning) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 234 | return err; |
| 235 | } |
| 236 | } |
| 237 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 238 | int status = 0; |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 239 | err = WebRtcAec_get_echo_status(cancellers_[handle_index]->state(), |
| 240 | &status); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 241 | if (err != AudioProcessing::kNoError) { |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 242 | return MapError(err); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | if (status == 1) { |
| 246 | stream_has_echo_ = true; |
| 247 | } |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 248 | |
| 249 | handle_index++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | was_stream_drift_set_ = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 254 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | int EchoCancellationImpl::Enable(bool enable) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 258 | // Run in a single-threaded manner. |
| 259 | rtc::CritScope cs_render(crit_render_); |
| 260 | rtc::CritScope cs_capture(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 261 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 262 | if (enable && !enabled_) { |
| 263 | enabled_ = enable; // Must be set before Initialize() is called. |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 264 | |
| 265 | // TODO(peah): Simplify once the Enable function has been removed from |
| 266 | // the public APM API. |
| 267 | RTC_DCHECK(stream_properties_); |
| 268 | Initialize(stream_properties_->sample_rate_hz, |
| 269 | stream_properties_->num_reverse_channels, |
| 270 | stream_properties_->num_output_channels, |
| 271 | stream_properties_->num_proc_channels); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 272 | } else { |
| 273 | enabled_ = enable; |
| 274 | } |
| 275 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 276 | } |
| 277 | |
peah | dc2242d | 2016-04-06 09:30:58 -0700 | [diff] [blame] | 278 | bool EchoCancellationImpl::is_enabled_render_side_query() const { |
| 279 | // TODO(peah): Add threadchecker. |
| 280 | rtc::CritScope cs_render(crit_render_); |
| 281 | return enabled_; |
| 282 | } |
| 283 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | bool EchoCancellationImpl::is_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 285 | rtc::CritScope cs(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 286 | return enabled_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 290 | { |
| 291 | if (MapSetting(level) == -1) { |
| 292 | return AudioProcessing::kBadParameterError; |
| 293 | } |
| 294 | rtc::CritScope cs(crit_capture_); |
| 295 | suppression_level_ = level; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 296 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | return Configure(); |
| 298 | } |
| 299 | |
| 300 | EchoCancellation::SuppressionLevel EchoCancellationImpl::suppression_level() |
| 301 | const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 302 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | return suppression_level_; |
| 304 | } |
| 305 | |
| 306 | int EchoCancellationImpl::enable_drift_compensation(bool enable) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 307 | { |
| 308 | rtc::CritScope cs(crit_capture_); |
| 309 | drift_compensation_enabled_ = enable; |
| 310 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | return Configure(); |
| 312 | } |
| 313 | |
| 314 | bool EchoCancellationImpl::is_drift_compensation_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 315 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | return drift_compensation_enabled_; |
| 317 | } |
| 318 | |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 319 | void EchoCancellationImpl::set_stream_drift_samples(int drift) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 320 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | was_stream_drift_set_ = true; |
| 322 | stream_drift_samples_ = drift; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | int EchoCancellationImpl::stream_drift_samples() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 326 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | return stream_drift_samples_; |
| 328 | } |
| 329 | |
| 330 | int EchoCancellationImpl::enable_metrics(bool enable) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 331 | { |
| 332 | rtc::CritScope cs(crit_capture_); |
| 333 | metrics_enabled_ = enable; |
| 334 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | return Configure(); |
| 336 | } |
| 337 | |
| 338 | bool EchoCancellationImpl::are_metrics_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 339 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 340 | return metrics_enabled_; |
| 341 | } |
| 342 | |
| 343 | // TODO(ajm): we currently just use the metrics from the first AEC. Think more |
| 344 | // aboue the best way to extend this to multi-channel. |
| 345 | int EchoCancellationImpl::GetMetrics(Metrics* metrics) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 346 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | if (metrics == NULL) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 348 | return AudioProcessing::kNullPointerError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 349 | } |
| 350 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 351 | if (!enabled_ || !metrics_enabled_) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 352 | return AudioProcessing::kNotEnabledError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | AecMetrics my_metrics; |
| 356 | memset(&my_metrics, 0, sizeof(my_metrics)); |
| 357 | memset(metrics, 0, sizeof(Metrics)); |
| 358 | |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 359 | const int err = WebRtcAec_GetMetrics(cancellers_[0]->state(), &my_metrics); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 360 | if (err != AudioProcessing::kNoError) { |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 361 | return MapError(err); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | metrics->residual_echo_return_loss.instant = my_metrics.rerl.instant; |
| 365 | metrics->residual_echo_return_loss.average = my_metrics.rerl.average; |
| 366 | metrics->residual_echo_return_loss.maximum = my_metrics.rerl.max; |
| 367 | metrics->residual_echo_return_loss.minimum = my_metrics.rerl.min; |
| 368 | |
| 369 | metrics->echo_return_loss.instant = my_metrics.erl.instant; |
| 370 | metrics->echo_return_loss.average = my_metrics.erl.average; |
| 371 | metrics->echo_return_loss.maximum = my_metrics.erl.max; |
| 372 | metrics->echo_return_loss.minimum = my_metrics.erl.min; |
| 373 | |
| 374 | metrics->echo_return_loss_enhancement.instant = my_metrics.erle.instant; |
| 375 | metrics->echo_return_loss_enhancement.average = my_metrics.erle.average; |
| 376 | metrics->echo_return_loss_enhancement.maximum = my_metrics.erle.max; |
| 377 | metrics->echo_return_loss_enhancement.minimum = my_metrics.erle.min; |
| 378 | |
| 379 | metrics->a_nlp.instant = my_metrics.aNlp.instant; |
| 380 | metrics->a_nlp.average = my_metrics.aNlp.average; |
| 381 | metrics->a_nlp.maximum = my_metrics.aNlp.max; |
| 382 | metrics->a_nlp.minimum = my_metrics.aNlp.min; |
| 383 | |
minyue | 5045337 | 2016-04-07 06:36:43 -0700 | [diff] [blame] | 384 | metrics->divergent_filter_fraction = my_metrics.divergent_filter_fraction; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 385 | return AudioProcessing::kNoError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | bool EchoCancellationImpl::stream_has_echo() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 389 | rtc::CritScope cs(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 390 | return stream_has_echo_; |
| 391 | } |
| 392 | |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 393 | int EchoCancellationImpl::enable_delay_logging(bool enable) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 394 | { |
| 395 | rtc::CritScope cs(crit_capture_); |
| 396 | delay_logging_enabled_ = enable; |
| 397 | } |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 398 | return Configure(); |
| 399 | } |
| 400 | |
| 401 | bool EchoCancellationImpl::is_delay_logging_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 402 | rtc::CritScope cs(crit_capture_); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 403 | return delay_logging_enabled_; |
| 404 | } |
| 405 | |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 406 | bool EchoCancellationImpl::is_delay_agnostic_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 407 | rtc::CritScope cs(crit_capture_); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 408 | return delay_agnostic_enabled_; |
| 409 | } |
| 410 | |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 411 | bool EchoCancellationImpl::is_aec3_enabled() const { |
peah | a332e2d | 2016-02-17 01:11:16 -0800 | [diff] [blame] | 412 | rtc::CritScope cs(crit_capture_); |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 413 | return aec3_enabled_; |
peah | a332e2d | 2016-02-17 01:11:16 -0800 | [diff] [blame] | 414 | } |
| 415 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 416 | std::string EchoCancellationImpl::GetExperimentsDescription() { |
| 417 | rtc::CritScope cs(crit_capture_); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 418 | std::string description = (aec3_enabled_ ? "AEC3" : ""); |
| 419 | if (refined_adaptive_filter_enabled_) { |
| 420 | description += ";RefinedAdaptiveFilter"; |
| 421 | } |
| 422 | return description; |
| 423 | } |
| 424 | |
| 425 | bool EchoCancellationImpl::is_refined_adaptive_filter_enabled() const { |
| 426 | rtc::CritScope cs(crit_capture_); |
| 427 | return refined_adaptive_filter_enabled_; |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 430 | bool EchoCancellationImpl::is_extended_filter_enabled() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 431 | rtc::CritScope cs(crit_capture_); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 432 | return extended_filter_enabled_; |
| 433 | } |
| 434 | |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 435 | // TODO(bjornv): How should we handle the multi-channel case? |
| 436 | int EchoCancellationImpl::GetDelayMetrics(int* median, int* std) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 437 | rtc::CritScope cs(crit_capture_); |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame] | 438 | float fraction_poor_delays = 0; |
| 439 | return GetDelayMetrics(median, std, &fraction_poor_delays); |
| 440 | } |
| 441 | |
| 442 | int EchoCancellationImpl::GetDelayMetrics(int* median, int* std, |
| 443 | float* fraction_poor_delays) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 444 | rtc::CritScope cs(crit_capture_); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 445 | if (median == NULL) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 446 | return AudioProcessing::kNullPointerError; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 447 | } |
| 448 | if (std == NULL) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 449 | return AudioProcessing::kNullPointerError; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 450 | } |
| 451 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 452 | if (!enabled_ || !delay_logging_enabled_) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 453 | return AudioProcessing::kNotEnabledError; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 454 | } |
| 455 | |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 456 | const int err = WebRtcAec_GetDelayMetrics(cancellers_[0]->state(), median, |
| 457 | std, fraction_poor_delays); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 458 | if (err != AudioProcessing::kNoError) { |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 459 | return MapError(err); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 460 | } |
| 461 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 462 | return AudioProcessing::kNoError; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 463 | } |
| 464 | |
bjornv@webrtc.org | 91d11b3 | 2013-03-05 16:53:09 +0000 | [diff] [blame] | 465 | struct AecCore* EchoCancellationImpl::aec_core() const { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 466 | rtc::CritScope cs(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 467 | if (!enabled_) { |
bjornv@webrtc.org | 91d11b3 | 2013-03-05 16:53:09 +0000 | [diff] [blame] | 468 | return NULL; |
| 469 | } |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 470 | return WebRtcAec_aec_core(cancellers_[0]->state()); |
bjornv@webrtc.org | 91d11b3 | 2013-03-05 16:53:09 +0000 | [diff] [blame] | 471 | } |
| 472 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 473 | void EchoCancellationImpl::Initialize(int sample_rate_hz, |
| 474 | size_t num_reverse_channels, |
| 475 | size_t num_output_channels, |
| 476 | size_t num_proc_channels) { |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 477 | rtc::CritScope cs_render(crit_render_); |
| 478 | rtc::CritScope cs_capture(crit_capture_); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 479 | |
| 480 | stream_properties_.reset( |
| 481 | new StreamProperties(sample_rate_hz, num_reverse_channels, |
| 482 | num_output_channels, num_proc_channels)); |
| 483 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 484 | if (!enabled_) { |
| 485 | return; |
| 486 | } |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 487 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 488 | if (NumCancellersRequired() > cancellers_.size()) { |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 489 | const size_t cancellers_old_size = cancellers_.size(); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 490 | cancellers_.resize(NumCancellersRequired()); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 491 | |
| 492 | for (size_t i = cancellers_old_size; i < cancellers_.size(); ++i) { |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 493 | cancellers_[i].reset(new Canceller()); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 494 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 495 | } |
| 496 | |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 497 | for (auto& canceller : cancellers_) { |
| 498 | canceller->Initialize(sample_rate_hz); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 499 | } |
solenberg | 92586f0 | 2016-03-04 12:29:03 -0800 | [diff] [blame] | 500 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 501 | Configure(); |
| 502 | |
| 503 | AllocateRenderQueue(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | } |
| 505 | |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 506 | int EchoCancellationImpl::GetSystemDelayInSamples() const { |
| 507 | rtc::CritScope cs(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 508 | RTC_DCHECK(enabled_); |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 509 | // Report the delay for the first AEC component. |
| 510 | return WebRtcAec_system_delay( |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 511 | WebRtcAec_aec_core(cancellers_[0]->state())); |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 512 | } |
| 513 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 514 | void EchoCancellationImpl::AllocateRenderQueue() { |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 515 | const size_t new_render_queue_element_max_size = std::max<size_t>( |
peah | 2446e5a | 2015-11-18 06:11:13 -0800 | [diff] [blame] | 516 | static_cast<size_t>(1), |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 517 | kMaxAllowedValuesOfSamplesPerFrame * NumCancellersRequired()); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 518 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 519 | rtc::CritScope cs_render(crit_render_); |
| 520 | rtc::CritScope cs_capture(crit_capture_); |
| 521 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 522 | // Reallocate the queue if the queue item size is too small to fit the |
| 523 | // data to put in the queue. |
peah | 2446e5a | 2015-11-18 06:11:13 -0800 | [diff] [blame] | 524 | if (render_queue_element_max_size_ < new_render_queue_element_max_size) { |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 525 | render_queue_element_max_size_ = new_render_queue_element_max_size; |
| 526 | |
| 527 | std::vector<float> template_queue_element(render_queue_element_max_size_); |
| 528 | |
| 529 | render_signal_queue_.reset( |
| 530 | new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
| 531 | kMaxNumFramesToBuffer, template_queue_element, |
| 532 | RenderQueueItemVerifier<float>(render_queue_element_max_size_))); |
peah | 2446e5a | 2015-11-18 06:11:13 -0800 | [diff] [blame] | 533 | |
| 534 | render_queue_buffer_.resize(render_queue_element_max_size_); |
| 535 | capture_queue_buffer_.resize(render_queue_element_max_size_); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 536 | } else { |
| 537 | render_signal_queue_->Clear(); |
| 538 | } |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 539 | } |
| 540 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 541 | void EchoCancellationImpl::SetExtraOptions(const Config& config) { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 542 | { |
| 543 | rtc::CritScope cs(crit_capture_); |
| 544 | extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; |
| 545 | delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 546 | refined_adaptive_filter_enabled_ = |
| 547 | config.Get<RefinedAdaptiveFilter>().enabled; |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 548 | aec3_enabled_ = config.Get<EchoCanceller3>().enabled; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 549 | } |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame] | 550 | Configure(); |
| 551 | } |
| 552 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 553 | int EchoCancellationImpl::Configure() { |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 554 | rtc::CritScope cs_render(crit_render_); |
| 555 | rtc::CritScope cs_capture(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 556 | AecConfig config; |
| 557 | config.metricsMode = metrics_enabled_; |
| 558 | config.nlpMode = MapSetting(suppression_level_); |
| 559 | config.skewMode = drift_compensation_enabled_; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 560 | config.delay_logging = delay_logging_enabled_; |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 561 | |
| 562 | int error = AudioProcessing::kNoError; |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 563 | for (auto& canceller : cancellers_) { |
| 564 | WebRtcAec_enable_extended_filter(WebRtcAec_aec_core(canceller->state()), |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 565 | extended_filter_enabled_ ? 1 : 0); |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 566 | WebRtcAec_enable_delay_agnostic(WebRtcAec_aec_core(canceller->state()), |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 567 | delay_agnostic_enabled_ ? 1 : 0); |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 568 | WebRtcAec_enable_aec3(WebRtcAec_aec_core(canceller->state()), |
| 569 | aec3_enabled_ ? 1 : 0); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 570 | WebRtcAec_enable_refined_adaptive_filter( |
| 571 | WebRtcAec_aec_core(canceller->state()), |
| 572 | refined_adaptive_filter_enabled_); |
peah | 4510bbd | 2016-03-07 22:50:14 -0800 | [diff] [blame] | 573 | const int handle_error = WebRtcAec_set_config(canceller->state(), config); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 574 | if (handle_error != AudioProcessing::kNoError) { |
| 575 | error = AudioProcessing::kNoError; |
| 576 | } |
| 577 | } |
| 578 | return error; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 579 | } |
| 580 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 581 | size_t EchoCancellationImpl::NumCancellersRequired() const { |
| 582 | RTC_DCHECK(stream_properties_); |
| 583 | return stream_properties_->num_output_channels * |
| 584 | stream_properties_->num_reverse_channels; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | } |
| 586 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 587 | } // namespace webrtc |