Line data Source code
1 : /*
2 : * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 :
11 : #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
12 : #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
13 :
14 : #include <memory>
15 : #include <vector>
16 :
17 : #include "webrtc/base/constructormagic.h"
18 : #include "webrtc/base/criticalsection.h"
19 : #include "webrtc/modules/audio_processing/include/audio_processing.h"
20 :
21 : namespace webrtc {
22 :
23 : class AudioBuffer;
24 :
25 0 : class EchoCancellationImpl : public EchoCancellation {
26 : public:
27 : EchoCancellationImpl(rtc::CriticalSection* crit_render,
28 : rtc::CriticalSection* crit_capture);
29 : ~EchoCancellationImpl() override;
30 :
31 : void ProcessRenderAudio(rtc::ArrayView<const float> packed_render_audio);
32 : int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
33 :
34 : // EchoCancellation implementation.
35 : bool is_enabled() const override;
36 : int stream_drift_samples() const override;
37 : SuppressionLevel suppression_level() const override;
38 : bool is_drift_compensation_enabled() const override;
39 :
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_);
44 : void SetExtraOptions(const webrtc::Config& config);
45 : bool is_delay_agnostic_enabled() const;
46 : bool is_extended_filter_enabled() const;
47 : std::string GetExperimentsDescription();
48 : bool is_refined_adaptive_filter_enabled() const;
49 :
50 : // Returns the system delay of the first AEC component.
51 : int GetSystemDelayInSamples() const;
52 :
53 : 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 :
60 : // 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 :
74 : private:
75 : class Canceller;
76 : struct StreamProperties;
77 :
78 : // EchoCancellation implementation.
79 : int Enable(bool enable) override;
80 : int enable_drift_compensation(bool enable) override;
81 : void set_stream_drift_samples(int drift) override;
82 : int set_suppression_level(SuppressionLevel level) override;
83 : bool are_metrics_enabled() const override;
84 : bool stream_has_echo() const override;
85 : bool is_delay_logging_enabled() const override;
86 : int GetDelayMetrics(int* median, int* std) override;
87 :
88 : struct AecCore* aec_core() const override;
89 :
90 : void AllocateRenderQueue();
91 : int Configure();
92 :
93 : rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_);
94 : rtc::CriticalSection* const crit_capture_;
95 :
96 : bool enabled_ = false;
97 : bool drift_compensation_enabled_ GUARDED_BY(crit_capture_);
98 : bool metrics_enabled_ GUARDED_BY(crit_capture_);
99 : SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_);
100 : int stream_drift_samples_ GUARDED_BY(crit_capture_);
101 : bool was_stream_drift_set_ GUARDED_BY(crit_capture_);
102 : bool stream_has_echo_ GUARDED_BY(crit_capture_);
103 : bool delay_logging_enabled_ GUARDED_BY(crit_capture_);
104 : bool extended_filter_enabled_ GUARDED_BY(crit_capture_);
105 : bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_);
106 : bool refined_adaptive_filter_enabled_ GUARDED_BY(crit_capture_) = false;
107 :
108 : std::vector<std::unique_ptr<Canceller>> cancellers_;
109 : std::unique_ptr<StreamProperties> stream_properties_;
110 :
111 : RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationImpl);
112 : };
113 :
114 : } // namespace webrtc
115 :
116 : #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
|