blob: 2ef6d52fe6b35504f7c42823f4c90b3603df4dea [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
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +000011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
12#define WEBRTC_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>
15
peahdf3efa82015-11-28 12:35:15 -080016#include "webrtc/base/criticalsection.h"
peahfa6228e2015-11-16 16:27:42 -080017#include "webrtc/common_audio/swap_queue.h"
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000018#include "webrtc/modules/audio_processing/include/audio_processing.h"
19#include "webrtc/modules/audio_processing/processing_component.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
solenberg92586f02016-03-04 12:29:03 -080025class EchoCancellationImpl : public EchoCancellation,
26 public ProcessingComponent {
niklase@google.com470e71d2011-07-07 08:21:25 +000027 public:
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000028 EchoCancellationImpl(const AudioProcessing* apm,
peahdf3efa82015-11-28 12:35:15 -080029 rtc::CriticalSection* crit_render,
30 rtc::CriticalSection* crit_capture);
niklase@google.com470e71d2011-07-07 08:21:25 +000031 virtual ~EchoCancellationImpl();
32
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000033 int ProcessRenderAudio(const AudioBuffer* audio);
34 int ProcessCaptureAudio(AudioBuffer* audio);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
36 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000037 bool is_enabled() const override;
38 int stream_drift_samples() const override;
Minyue13b96ba2015-10-03 00:39:14 +020039 SuppressionLevel suppression_level() const override;
40 bool is_drift_compensation_enabled() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
solenberg92586f02016-03-04 12:29:03 -080042 // ProcessingComponent implementation.
43 int Initialize() override;
44 void SetExtraOptions(const Config& config) override;
Minyue13b96ba2015-10-03 00:39:14 +020045 bool is_delay_agnostic_enabled() const;
46 bool is_extended_filter_enabled() const;
peaha332e2d2016-02-17 01:11:16 -080047 bool is_next_generation_aec_enabled() const;
Minyue13b96ba2015-10-03 00:39:14 +020048
peahfa6228e2015-11-16 16:27:42 -080049 // Reads render side data that has been queued on the render call.
peahdf3efa82015-11-28 12:35:15 -080050 // Called holding the capture lock.
peahfa6228e2015-11-16 16:27:42 -080051 void ReadQueuedRenderData();
52
peah20028c42016-03-04 11:50:54 -080053 // Returns the system delay of the first AEC component.
54 int GetSystemDelayInSamples() const;
55
niklase@google.com470e71d2011-07-07 08:21:25 +000056 private:
57 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000058 int Enable(bool enable) override;
59 int enable_drift_compensation(bool enable) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000060 void set_stream_drift_samples(int drift) override;
61 int set_suppression_level(SuppressionLevel level) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 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;
peahdf3efa82015-11-28 12:35:15 -080072
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000073 struct AecCore* aec_core() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000074
solenberg92586f02016-03-04 12:29:03 -080075 // ProcessingComponent implementation.
76 void* CreateHandle() const override;
77 int InitializeHandle(void* handle) const override;
78 int ConfigureHandle(void* handle) const override;
79 void DestroyHandle(void* handle) const override;
80 size_t num_handles_required() const override;
81 int GetHandleError(void* handle) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
peahfa6228e2015-11-16 16:27:42 -080083 void AllocateRenderQueue();
84
peahdf3efa82015-11-28 12:35:15 -080085 // Not guarded as its public API is thread safe.
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000086 const AudioProcessing* apm_;
peah81b9bfe2015-11-27 02:47:28 -080087
peahdf3efa82015-11-28 12:35:15 -080088 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_);
89 rtc::CriticalSection* const crit_capture_;
peahfa6228e2015-11-16 16:27:42 -080090
peahdf3efa82015-11-28 12:35:15 -080091 bool drift_compensation_enabled_ GUARDED_BY(crit_capture_);
92 bool metrics_enabled_ GUARDED_BY(crit_capture_);
93 SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_);
94 int stream_drift_samples_ GUARDED_BY(crit_capture_);
95 bool was_stream_drift_set_ GUARDED_BY(crit_capture_);
96 bool stream_has_echo_ GUARDED_BY(crit_capture_);
97 bool delay_logging_enabled_ GUARDED_BY(crit_capture_);
98 bool extended_filter_enabled_ GUARDED_BY(crit_capture_);
99 bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_);
peaha332e2d2016-02-17 01:11:16 -0800100 bool next_generation_aec_enabled_ GUARDED_BY(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800101
102 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_)
103 GUARDED_BY(crit_capture_);
104 std::vector<float> render_queue_buffer_ GUARDED_BY(crit_render_);
105 std::vector<float> capture_queue_buffer_ GUARDED_BY(crit_capture_);
106
107 // Lock protection not needed.
kwiberg88788ad2016-02-19 07:04:49 -0800108 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
peahfa6228e2015-11-16 16:27:42 -0800109 render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110};
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000111
niklase@google.com470e71d2011-07-07 08:21:25 +0000112} // namespace webrtc
113
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +0000114#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_