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 | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 14 | #include <memory> |
terelius | 85fa7d5 | 2016-03-24 01:51:52 -0700 | [diff] [blame] | 15 | #include <vector> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 16 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 17 | #include "webrtc/base/constructormagic.h" |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 18 | #include "webrtc/base/criticalsection.h" |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | class AudioBuffer; |
| 24 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 25 | class EchoCancellationImpl : public EchoCancellation { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | public: |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 27 | EchoCancellationImpl(rtc::CriticalSection* crit_render, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 28 | rtc::CriticalSection* crit_capture); |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 29 | ~EchoCancellationImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 31 | void ProcessRenderAudio(rtc::ArrayView<const float> packed_render_audio); |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 32 | int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
| 34 | // EchoCancellation implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 35 | bool is_enabled() const override; |
| 36 | int stream_drift_samples() const override; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 37 | SuppressionLevel suppression_level() const override; |
| 38 | bool is_drift_compensation_enabled() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 40 | void Initialize(int sample_rate_hz, |
| 41 | size_t num_reverse_channels_, |
| 42 | size_t num_output_channels_, |
| 43 | size_t num_proc_channels_); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 44 | void SetExtraOptions(const webrtc::Config& config); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 45 | bool is_delay_agnostic_enabled() const; |
| 46 | bool is_extended_filter_enabled() const; |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 47 | bool is_aec3_enabled() const; |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 48 | std::string GetExperimentsDescription(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 49 | bool is_refined_adaptive_filter_enabled() const; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 50 | |
peah | 20028c4 | 2016-03-04 11:50:54 -0800 | [diff] [blame] | 51 | // Returns the system delay of the first AEC component. |
| 52 | int GetSystemDelayInSamples() const; |
| 53 | |
peah | 764e364 | 2016-10-22 05:04:30 -0700 | [diff] [blame] | 54 | static void PackRenderAudioBuffer(const AudioBuffer* audio, |
| 55 | size_t num_output_channels, |
| 56 | size_t num_channels, |
| 57 | std::vector<float>* packed_buffer); |
| 58 | static size_t NumCancellersRequired(size_t num_output_channels, |
| 59 | size_t num_reverse_channels); |
| 60 | |
ivoc | 3e9a537 | 2016-10-28 07:55:33 -0700 | [diff] [blame] | 61 | // Enable logging of various AEC statistics. |
| 62 | int enable_metrics(bool enable) override; |
| 63 | |
| 64 | // Provides various statistics about the AEC. |
| 65 | int GetMetrics(Metrics* metrics) override; |
| 66 | |
| 67 | // Enable logging of delay metrics. |
| 68 | int enable_delay_logging(bool enable) override; |
| 69 | |
| 70 | // Provides delay metrics. |
| 71 | int GetDelayMetrics(int* median, |
| 72 | int* std, |
| 73 | float* fraction_poor_delays) override; |
| 74 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | private: |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 76 | class Canceller; |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 77 | struct StreamProperties; |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 78 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | // EchoCancellation implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 80 | int Enable(bool enable) override; |
| 81 | int enable_drift_compensation(bool enable) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 82 | void set_stream_drift_samples(int drift) override; |
| 83 | int set_suppression_level(SuppressionLevel level) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 84 | bool are_metrics_enabled() const override; |
| 85 | bool stream_has_echo() const override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 86 | bool is_delay_logging_enabled() const override; |
| 87 | int GetDelayMetrics(int* median, int* std) override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 88 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 89 | struct AecCore* aec_core() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 91 | void AllocateRenderQueue(); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 92 | int Configure(); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 93 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 94 | rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); |
| 95 | rtc::CriticalSection* const crit_capture_; |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 96 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 97 | bool enabled_ = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 98 | bool drift_compensation_enabled_ GUARDED_BY(crit_capture_); |
| 99 | bool metrics_enabled_ GUARDED_BY(crit_capture_); |
| 100 | SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_); |
| 101 | int stream_drift_samples_ GUARDED_BY(crit_capture_); |
| 102 | bool was_stream_drift_set_ GUARDED_BY(crit_capture_); |
| 103 | bool stream_has_echo_ GUARDED_BY(crit_capture_); |
| 104 | bool delay_logging_enabled_ GUARDED_BY(crit_capture_); |
| 105 | bool extended_filter_enabled_ GUARDED_BY(crit_capture_); |
| 106 | bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_); |
peah | 6ebc4d3 | 2016-03-07 16:59:39 -0800 | [diff] [blame] | 107 | bool aec3_enabled_ GUARDED_BY(crit_capture_); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 108 | bool refined_adaptive_filter_enabled_ GUARDED_BY(crit_capture_) = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 109 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 110 | std::vector<std::unique_ptr<Canceller>> cancellers_; |
peah | b58a158 | 2016-03-15 09:34:24 -0700 | [diff] [blame] | 111 | std::unique_ptr<StreamProperties> stream_properties_; |
| 112 | |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 113 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationImpl); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | }; |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 115 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | } // namespace webrtc |
| 117 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 118 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |