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 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame^] | 14 | #include "webrtc/base/scoped_ptr.h" |
| 15 | #include "webrtc/common_audio/swap_queue.h" |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 17 | #include "webrtc/modules/audio_processing/processing_component.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | class AudioBuffer; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 22 | class CriticalSectionWrapper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 24 | class EchoCancellationImpl : public EchoCancellation, |
| 25 | public ProcessingComponent { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | public: |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 27 | EchoCancellationImpl(const AudioProcessing* apm, |
| 28 | CriticalSectionWrapper* crit); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | virtual ~EchoCancellationImpl(); |
| 30 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 31 | int ProcessRenderAudio(const AudioBuffer* audio); |
| 32 | int ProcessCaptureAudio(AudioBuffer* audio); |
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 | |
| 40 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 41 | int Initialize() override; |
| 42 | void SetExtraOptions(const Config& config) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 44 | bool is_delay_agnostic_enabled() const; |
| 45 | bool is_extended_filter_enabled() const; |
| 46 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame^] | 47 | // Reads render side data that has been queued on the render call. |
| 48 | void ReadQueuedRenderData(); |
| 49 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | private: |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame^] | 51 | static const size_t kAllowedValuesOfSamplesPerFrame1 = 80; |
| 52 | static const size_t kAllowedValuesOfSamplesPerFrame2 = 160; |
| 53 | // TODO(peah): Decrease this once we properly handle hugely unbalanced |
| 54 | // reverse and forward call numbers. |
| 55 | static const size_t kMaxNumFramesToBuffer = 100; |
| 56 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | // EchoCancellation implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 58 | int Enable(bool enable) override; |
| 59 | int enable_drift_compensation(bool enable) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 60 | void set_stream_drift_samples(int drift) override; |
| 61 | int set_suppression_level(SuppressionLevel level) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 62 | int enable_metrics(bool enable) override; |
| 63 | bool are_metrics_enabled() const override; |
| 64 | bool stream_has_echo() const override; |
| 65 | int GetMetrics(Metrics* metrics) override; |
| 66 | int enable_delay_logging(bool enable) override; |
| 67 | bool is_delay_logging_enabled() const override; |
| 68 | int GetDelayMetrics(int* median, int* std) override; |
| 69 | int GetDelayMetrics(int* median, |
| 70 | int* std, |
| 71 | float* fraction_poor_delays) override; |
| 72 | struct AecCore* aec_core() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
| 74 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 75 | void* CreateHandle() const override; |
| 76 | int InitializeHandle(void* handle) const override; |
| 77 | int ConfigureHandle(void* handle) const override; |
| 78 | void DestroyHandle(void* handle) const override; |
| 79 | int num_handles_required() const override; |
| 80 | int GetHandleError(void* handle) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame^] | 82 | void AllocateRenderQueue(); |
| 83 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 84 | const AudioProcessing* apm_; |
| 85 | CriticalSectionWrapper* crit_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | bool drift_compensation_enabled_; |
| 87 | bool metrics_enabled_; |
| 88 | SuppressionLevel suppression_level_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | int stream_drift_samples_; |
| 90 | bool was_stream_drift_set_; |
| 91 | bool stream_has_echo_; |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 92 | bool delay_logging_enabled_; |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 93 | bool extended_filter_enabled_; |
henrik.lundin | 0f133b9 | 2015-07-02 00:17:55 -0700 | [diff] [blame] | 94 | bool delay_agnostic_enabled_; |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame^] | 95 | |
| 96 | size_t render_queue_element_max_size_; |
| 97 | std::vector<float> render_queue_buffer_; |
| 98 | std::vector<float> capture_queue_buffer_; |
| 99 | rtc::scoped_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>> |
| 100 | render_signal_queue_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | }; |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 102 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | } // namespace webrtc |
| 104 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 105 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |