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> |
| 15 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 17 | #include "webrtc/common_audio/swap_queue.h" |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 19 | #include "webrtc/modules/audio_processing/processing_component.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 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 25 | class EchoCancellationImpl : public EchoCancellation, |
| 26 | public ProcessingComponent { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | public: |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 28 | EchoCancellationImpl(const AudioProcessing* apm, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 29 | rtc::CriticalSection* crit_render, |
| 30 | rtc::CriticalSection* crit_capture); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | virtual ~EchoCancellationImpl(); |
| 32 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 33 | int ProcessRenderAudio(const AudioBuffer* audio); |
| 34 | int ProcessCaptureAudio(AudioBuffer* audio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
| 36 | // EchoCancellation implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 37 | bool is_enabled() const override; |
| 38 | int stream_drift_samples() const override; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 39 | SuppressionLevel suppression_level() const override; |
| 40 | bool is_drift_compensation_enabled() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
| 42 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 43 | int Initialize() override; |
| 44 | void SetExtraOptions(const Config& config) override; |
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 | a332e2d | 2016-02-17 01:11:16 -0800 | [diff] [blame] | 47 | bool is_next_generation_aec_enabled() const; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 48 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 49 | // Reads render side data that has been queued on the render call. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 50 | // Called holding the capture lock. |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 51 | void ReadQueuedRenderData(); |
| 52 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | private: |
| 54 | // EchoCancellation implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 55 | int Enable(bool enable) override; |
| 56 | int enable_drift_compensation(bool enable) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 57 | void set_stream_drift_samples(int drift) override; |
| 58 | int set_suppression_level(SuppressionLevel level) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 59 | int enable_metrics(bool enable) override; |
| 60 | bool are_metrics_enabled() const override; |
| 61 | bool stream_has_echo() const override; |
| 62 | int GetMetrics(Metrics* metrics) override; |
| 63 | int enable_delay_logging(bool enable) override; |
| 64 | bool is_delay_logging_enabled() const override; |
| 65 | int GetDelayMetrics(int* median, int* std) override; |
| 66 | int GetDelayMetrics(int* median, |
| 67 | int* std, |
| 68 | float* fraction_poor_delays) override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 69 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 70 | struct AecCore* aec_core() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
| 72 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 73 | void* CreateHandle() const override; |
| 74 | int InitializeHandle(void* handle) const override; |
| 75 | int ConfigureHandle(void* handle) const override; |
| 76 | void DestroyHandle(void* handle) const override; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 77 | size_t num_handles_required() const override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 78 | int GetHandleError(void* handle) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 80 | void AllocateRenderQueue(); |
| 81 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 82 | // Not guarded as its public API is thread safe. |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 83 | const AudioProcessing* apm_; |
peah | 81b9bfe | 2015-11-27 02:47:28 -0800 | [diff] [blame] | 84 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 85 | rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); |
| 86 | rtc::CriticalSection* const crit_capture_; |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 87 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 88 | bool drift_compensation_enabled_ GUARDED_BY(crit_capture_); |
| 89 | bool metrics_enabled_ GUARDED_BY(crit_capture_); |
| 90 | SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_); |
| 91 | int stream_drift_samples_ GUARDED_BY(crit_capture_); |
| 92 | bool was_stream_drift_set_ GUARDED_BY(crit_capture_); |
| 93 | bool stream_has_echo_ GUARDED_BY(crit_capture_); |
| 94 | bool delay_logging_enabled_ GUARDED_BY(crit_capture_); |
| 95 | bool extended_filter_enabled_ GUARDED_BY(crit_capture_); |
| 96 | bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_); |
peah | a332e2d | 2016-02-17 01:11:16 -0800 | [diff] [blame] | 97 | bool next_generation_aec_enabled_ GUARDED_BY(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 98 | |
| 99 | size_t render_queue_element_max_size_ GUARDED_BY(crit_render_) |
| 100 | GUARDED_BY(crit_capture_); |
| 101 | std::vector<float> render_queue_buffer_ GUARDED_BY(crit_render_); |
| 102 | std::vector<float> capture_queue_buffer_ GUARDED_BY(crit_capture_); |
| 103 | |
| 104 | // Lock protection not needed. |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame^] | 105 | std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>> |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 106 | render_signal_queue_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | }; |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 108 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | } // namespace webrtc |
| 110 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 111 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |