blob: d410a11578c82098ade935f8ed520d9f8cbe8022 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
12#define MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwiberg88788ad2016-02-19 07:04:49 -080014#include <memory>
terelius85fa7d52016-03-24 01:51:52 -070015#include <vector>
kwiberg88788ad2016-02-19 07:04:49 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_processing/include/audio_processing.h"
18#include "rtc_base/constructormagic.h"
19#include "rtc_base/criticalsection.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000022
niklase@google.com470e71d2011-07-07 08:21:25 +000023class AudioBuffer;
24
peahb624d8c2016-03-05 03:01:14 -080025class EchoCancellationImpl : public EchoCancellation {
niklase@google.com470e71d2011-07-07 08:21:25 +000026 public:
peahb58a1582016-03-15 09:34:24 -070027 EchoCancellationImpl(rtc::CriticalSection* crit_render,
peahdf3efa82015-11-28 12:35:15 -080028 rtc::CriticalSection* crit_capture);
kwiberg83ffe452016-08-29 14:46:07 -070029 ~EchoCancellationImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
peah764e3642016-10-22 05:04:30 -070031 void ProcessRenderAudio(rtc::ArrayView<const float> packed_render_audio);
peahb58a1582016-03-15 09:34:24 -070032 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
34 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000035 bool is_enabled() const override;
36 int stream_drift_samples() const override;
Minyue13b96ba2015-10-03 00:39:14 +020037 SuppressionLevel suppression_level() const override;
38 bool is_drift_compensation_enabled() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
peahb58a1582016-03-15 09:34:24 -070040 void Initialize(int sample_rate_hz,
41 size_t num_reverse_channels_,
42 size_t num_output_channels_,
43 size_t num_proc_channels_);
peah88ac8532016-09-12 16:47:25 -070044 void SetExtraOptions(const webrtc::Config& config);
Minyue13b96ba2015-10-03 00:39:14 +020045 bool is_delay_agnostic_enabled() const;
46 bool is_extended_filter_enabled() const;
peah7789fe72016-04-15 01:19:44 -070047 std::string GetExperimentsDescription();
peah0332c2d2016-04-15 11:23:33 -070048 bool is_refined_adaptive_filter_enabled() const;
Minyue13b96ba2015-10-03 00:39:14 +020049
peah20028c42016-03-04 11:50:54 -080050 // Returns the system delay of the first AEC component.
51 int GetSystemDelayInSamples() const;
52
peah764e3642016-10-22 05:04:30 -070053 static void PackRenderAudioBuffer(const AudioBuffer* audio,
54 size_t num_output_channels,
55 size_t num_channels,
56 std::vector<float>* packed_buffer);
57 static size_t NumCancellersRequired(size_t num_output_channels,
58 size_t num_reverse_channels);
59
ivoc3e9a5372016-10-28 07:55:33 -070060 // Enable logging of various AEC statistics.
61 int enable_metrics(bool enable) override;
62
63 // Provides various statistics about the AEC.
64 int GetMetrics(Metrics* metrics) override;
65
66 // Enable logging of delay metrics.
67 int enable_delay_logging(bool enable) override;
68
69 // Provides delay metrics.
70 int GetDelayMetrics(int* median,
71 int* std,
72 float* fraction_poor_delays) override;
73
niklase@google.com470e71d2011-07-07 08:21:25 +000074 private:
peahb624d8c2016-03-05 03:01:14 -080075 class Canceller;
peahb58a1582016-03-15 09:34:24 -070076 struct StreamProperties;
peahb624d8c2016-03-05 03:01:14 -080077
niklase@google.com470e71d2011-07-07 08:21:25 +000078 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000079 int Enable(bool enable) override;
80 int enable_drift_compensation(bool enable) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000081 void set_stream_drift_samples(int drift) override;
82 int set_suppression_level(SuppressionLevel level) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000083 bool are_metrics_enabled() const override;
84 bool stream_has_echo() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000085 bool is_delay_logging_enabled() const override;
86 int GetDelayMetrics(int* median, int* std) override;
peahdf3efa82015-11-28 12:35:15 -080087
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000088 struct AecCore* aec_core() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000089
peahfa6228e2015-11-16 16:27:42 -080090 void AllocateRenderQueue();
peahb624d8c2016-03-05 03:01:14 -080091 int Configure();
peahfa6228e2015-11-16 16:27:42 -080092
danilchap56359be2017-09-07 07:53:45 -070093 rtc::CriticalSection* const crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -080094 rtc::CriticalSection* const crit_capture_;
peahfa6228e2015-11-16 16:27:42 -080095
peahb624d8c2016-03-05 03:01:14 -080096 bool enabled_ = false;
danilchap56359be2017-09-07 07:53:45 -070097 bool drift_compensation_enabled_ RTC_GUARDED_BY(crit_capture_);
98 bool metrics_enabled_ RTC_GUARDED_BY(crit_capture_);
99 SuppressionLevel suppression_level_ RTC_GUARDED_BY(crit_capture_);
100 int stream_drift_samples_ RTC_GUARDED_BY(crit_capture_);
101 bool was_stream_drift_set_ RTC_GUARDED_BY(crit_capture_);
102 bool stream_has_echo_ RTC_GUARDED_BY(crit_capture_);
103 bool delay_logging_enabled_ RTC_GUARDED_BY(crit_capture_);
104 bool extended_filter_enabled_ RTC_GUARDED_BY(crit_capture_);
105 bool delay_agnostic_enabled_ RTC_GUARDED_BY(crit_capture_);
106 bool refined_adaptive_filter_enabled_ RTC_GUARDED_BY(crit_capture_) = false;
peahdf3efa82015-11-28 12:35:15 -0800107
peahb624d8c2016-03-05 03:01:14 -0800108 std::vector<std::unique_ptr<Canceller>> cancellers_;
peahb58a1582016-03-15 09:34:24 -0700109 std::unique_ptr<StreamProperties> stream_properties_;
110
peahb624d8c2016-03-05 03:01:14 -0800111 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationImpl);
niklase@google.com470e71d2011-07-07 08:21:25 +0000112};
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000113
niklase@google.com470e71d2011-07-07 08:21:25 +0000114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_