OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
18 #include "webrtc/common_audio/swap_queue.h" | 18 #include "webrtc/common_audio/swap_queue.h" |
19 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 19 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
20 #include "webrtc/modules/audio_processing/render_queue_item_verifier.h" | 20 #include "webrtc/modules/audio_processing/render_queue_item_verifier.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 class AudioBuffer; | 24 class AudioBuffer; |
25 | 25 |
26 class EchoCancellationImpl : public EchoCancellation { | 26 class EchoCancellationImpl : public EchoCancellation { |
27 public: | 27 public: |
28 EchoCancellationImpl(const AudioProcessing* apm, | 28 EchoCancellationImpl(rtc::CriticalSection* crit_render, |
29 rtc::CriticalSection* crit_render, | |
30 rtc::CriticalSection* crit_capture); | 29 rtc::CriticalSection* crit_capture); |
31 virtual ~EchoCancellationImpl(); | 30 virtual ~EchoCancellationImpl(); |
32 | 31 |
33 int ProcessRenderAudio(const AudioBuffer* audio); | 32 int ProcessRenderAudio(const AudioBuffer* audio); |
34 int ProcessCaptureAudio(AudioBuffer* audio); | 33 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms); |
35 | 34 |
36 // EchoCancellation implementation. | 35 // EchoCancellation implementation. |
37 bool is_enabled() const override; | 36 bool is_enabled() const override; |
38 int stream_drift_samples() const override; | 37 int stream_drift_samples() const override; |
39 SuppressionLevel suppression_level() const override; | 38 SuppressionLevel suppression_level() const override; |
40 bool is_drift_compensation_enabled() const override; | 39 bool is_drift_compensation_enabled() const override; |
41 | 40 |
42 void Initialize(); | 41 void Initialize(int sample_rate_hz, |
| 42 size_t num_reverse_channels_, |
| 43 size_t num_output_channels_, |
| 44 size_t num_proc_channels_); |
43 void SetExtraOptions(const Config& config); | 45 void SetExtraOptions(const Config& config); |
44 bool is_delay_agnostic_enabled() const; | 46 bool is_delay_agnostic_enabled() const; |
45 bool is_extended_filter_enabled() const; | 47 bool is_extended_filter_enabled() const; |
46 bool is_aec3_enabled() const; | 48 bool is_aec3_enabled() const; |
47 | 49 |
48 // Reads render side data that has been queued on the render call. | 50 // Reads render side data that has been queued on the render call. |
49 // Called holding the capture lock. | 51 // Called holding the capture lock. |
50 void ReadQueuedRenderData(); | 52 void ReadQueuedRenderData(); |
51 | 53 |
52 // Returns the system delay of the first AEC component. | 54 // Returns the system delay of the first AEC component. |
53 int GetSystemDelayInSamples() const; | 55 int GetSystemDelayInSamples() const; |
54 | 56 |
55 private: | 57 private: |
56 class Canceller; | 58 class Canceller; |
| 59 struct StreamProperties; |
57 | 60 |
58 // EchoCancellation implementation. | 61 // EchoCancellation implementation. |
59 int Enable(bool enable) override; | 62 int Enable(bool enable) override; |
60 int enable_drift_compensation(bool enable) override; | 63 int enable_drift_compensation(bool enable) override; |
61 void set_stream_drift_samples(int drift) override; | 64 void set_stream_drift_samples(int drift) override; |
62 int set_suppression_level(SuppressionLevel level) override; | 65 int set_suppression_level(SuppressionLevel level) override; |
63 int enable_metrics(bool enable) override; | 66 int enable_metrics(bool enable) override; |
64 bool are_metrics_enabled() const override; | 67 bool are_metrics_enabled() const override; |
65 bool stream_has_echo() const override; | 68 bool stream_has_echo() const override; |
66 int GetMetrics(Metrics* metrics) override; | 69 int GetMetrics(Metrics* metrics) override; |
67 int enable_delay_logging(bool enable) override; | 70 int enable_delay_logging(bool enable) override; |
68 bool is_delay_logging_enabled() const override; | 71 bool is_delay_logging_enabled() const override; |
69 int GetDelayMetrics(int* median, int* std) override; | 72 int GetDelayMetrics(int* median, int* std) override; |
70 int GetDelayMetrics(int* median, | 73 int GetDelayMetrics(int* median, |
71 int* std, | 74 int* std, |
72 float* fraction_poor_delays) override; | 75 float* fraction_poor_delays) override; |
73 | 76 |
74 struct AecCore* aec_core() const override; | 77 struct AecCore* aec_core() const override; |
75 | 78 |
76 size_t num_handles_required() const; | 79 size_t NumCancellersRequired() const; |
77 | 80 |
78 void AllocateRenderQueue(); | 81 void AllocateRenderQueue(); |
79 int Configure(); | 82 int Configure(); |
80 | 83 |
81 // Not guarded as its public API is thread safe. | |
82 const AudioProcessing* apm_; | |
83 | |
84 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); | 84 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); |
85 rtc::CriticalSection* const crit_capture_; | 85 rtc::CriticalSection* const crit_capture_; |
86 | 86 |
87 bool enabled_ = false; | 87 bool enabled_ = false; |
88 bool drift_compensation_enabled_ GUARDED_BY(crit_capture_); | 88 bool drift_compensation_enabled_ GUARDED_BY(crit_capture_); |
89 bool metrics_enabled_ GUARDED_BY(crit_capture_); | 89 bool metrics_enabled_ GUARDED_BY(crit_capture_); |
90 SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_); | 90 SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_); |
91 int stream_drift_samples_ GUARDED_BY(crit_capture_); | 91 int stream_drift_samples_ GUARDED_BY(crit_capture_); |
92 bool was_stream_drift_set_ GUARDED_BY(crit_capture_); | 92 bool was_stream_drift_set_ GUARDED_BY(crit_capture_); |
93 bool stream_has_echo_ GUARDED_BY(crit_capture_); | 93 bool stream_has_echo_ GUARDED_BY(crit_capture_); |
94 bool delay_logging_enabled_ GUARDED_BY(crit_capture_); | 94 bool delay_logging_enabled_ GUARDED_BY(crit_capture_); |
95 bool extended_filter_enabled_ GUARDED_BY(crit_capture_); | 95 bool extended_filter_enabled_ GUARDED_BY(crit_capture_); |
96 bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_); | 96 bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_); |
97 bool aec3_enabled_ GUARDED_BY(crit_capture_); | 97 bool aec3_enabled_ GUARDED_BY(crit_capture_); |
98 | 98 |
99 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_) | 99 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_) |
100 GUARDED_BY(crit_capture_); | 100 GUARDED_BY(crit_capture_); |
101 std::vector<float> render_queue_buffer_ GUARDED_BY(crit_render_); | 101 std::vector<float> render_queue_buffer_ GUARDED_BY(crit_render_); |
102 std::vector<float> capture_queue_buffer_ GUARDED_BY(crit_capture_); | 102 std::vector<float> capture_queue_buffer_ GUARDED_BY(crit_capture_); |
103 | 103 |
104 // Lock protection not needed. | 104 // Lock protection not needed. |
105 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>> | 105 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>> |
106 render_signal_queue_; | 106 render_signal_queue_; |
107 | 107 |
108 std::vector<std::unique_ptr<Canceller>> cancellers_; | 108 std::vector<std::unique_ptr<Canceller>> cancellers_; |
| 109 std::unique_ptr<StreamProperties> stream_properties_; |
| 110 |
109 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationImpl); | 111 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationImpl); |
110 }; | 112 }; |
111 | 113 |
112 } // namespace webrtc | 114 } // namespace webrtc |
113 | 115 |
114 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ | 116 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
OLD | NEW |