blob: 9418fbfed79af72a3989fa74ecfce1863cd74758 [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
peahdf3efa82015-11-28 12:35:15 -080014#include "webrtc/base/criticalsection.h"
peahfa6228e2015-11-16 16:27:42 -080015#include "webrtc/base/scoped_ptr.h"
16#include "webrtc/common_audio/swap_queue.h"
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000017#include "webrtc/modules/audio_processing/include/audio_processing.h"
18#include "webrtc/modules/audio_processing/processing_component.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20namespace webrtc {
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000021
niklase@google.com470e71d2011-07-07 08:21:25 +000022class AudioBuffer;
23
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000024class EchoCancellationImpl : public EchoCancellation,
25 public ProcessingComponent {
niklase@google.com470e71d2011-07-07 08:21:25 +000026 public:
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000027 EchoCancellationImpl(const AudioProcessing* apm,
peahdf3efa82015-11-28 12:35:15 -080028 rtc::CriticalSection* crit_render,
29 rtc::CriticalSection* crit_capture);
niklase@google.com470e71d2011-07-07 08:21:25 +000030 virtual ~EchoCancellationImpl();
31
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000032 int ProcessRenderAudio(const AudioBuffer* audio);
33 int ProcessCaptureAudio(AudioBuffer* audio);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
35 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 bool is_enabled() const override;
37 int stream_drift_samples() const override;
Minyue13b96ba2015-10-03 00:39:14 +020038 SuppressionLevel suppression_level() const override;
39 bool is_drift_compensation_enabled() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000040
41 // ProcessingComponent implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000042 int Initialize() override;
43 void SetExtraOptions(const Config& config) override;
Minyue13b96ba2015-10-03 00:39:14 +020044 bool is_delay_agnostic_enabled() const;
45 bool is_extended_filter_enabled() const;
46
peahfa6228e2015-11-16 16:27:42 -080047 // Reads render side data that has been queued on the render call.
peahdf3efa82015-11-28 12:35:15 -080048 // Called holding the capture lock.
peahfa6228e2015-11-16 16:27:42 -080049 void ReadQueuedRenderData();
50
niklase@google.com470e71d2011-07-07 08:21:25 +000051 private:
52 // EchoCancellation implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000053 int Enable(bool enable) override;
54 int enable_drift_compensation(bool enable) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000055 void set_stream_drift_samples(int drift) override;
56 int set_suppression_level(SuppressionLevel level) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 int enable_metrics(bool enable) override;
58 bool are_metrics_enabled() const override;
59 bool stream_has_echo() const override;
60 int GetMetrics(Metrics* metrics) override;
61 int enable_delay_logging(bool enable) override;
62 bool is_delay_logging_enabled() const override;
63 int GetDelayMetrics(int* median, int* std) override;
64 int GetDelayMetrics(int* median,
65 int* std,
66 float* fraction_poor_delays) override;
peahdf3efa82015-11-28 12:35:15 -080067
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000068 struct AecCore* aec_core() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
70 // ProcessingComponent implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000071 void* CreateHandle() const override;
72 int InitializeHandle(void* handle) const override;
73 int ConfigureHandle(void* handle) const override;
74 void DestroyHandle(void* handle) const override;
75 int num_handles_required() const override;
76 int GetHandleError(void* handle) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
peahfa6228e2015-11-16 16:27:42 -080078 void AllocateRenderQueue();
79
peahdf3efa82015-11-28 12:35:15 -080080 // Not guarded as its public API is thread safe.
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000081 const AudioProcessing* apm_;
peah81b9bfe2015-11-27 02:47:28 -080082
peahdf3efa82015-11-28 12:35:15 -080083 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_);
84 rtc::CriticalSection* const crit_capture_;
peahfa6228e2015-11-16 16:27:42 -080085
peahdf3efa82015-11-28 12:35:15 -080086 bool drift_compensation_enabled_ GUARDED_BY(crit_capture_);
87 bool metrics_enabled_ GUARDED_BY(crit_capture_);
88 SuppressionLevel suppression_level_ GUARDED_BY(crit_capture_);
89 int stream_drift_samples_ GUARDED_BY(crit_capture_);
90 bool was_stream_drift_set_ GUARDED_BY(crit_capture_);
91 bool stream_has_echo_ GUARDED_BY(crit_capture_);
92 bool delay_logging_enabled_ GUARDED_BY(crit_capture_);
93 bool extended_filter_enabled_ GUARDED_BY(crit_capture_);
94 bool delay_agnostic_enabled_ GUARDED_BY(crit_capture_);
95
96 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_)
97 GUARDED_BY(crit_capture_);
98 std::vector<float> render_queue_buffer_ GUARDED_BY(crit_render_);
99 std::vector<float> capture_queue_buffer_ GUARDED_BY(crit_capture_);
100
101 // Lock protection not needed.
peahfa6228e2015-11-16 16:27:42 -0800102 rtc::scoped_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
103 render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104};
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000105
niklase@google.com470e71d2011-07-07 08:21:25 +0000106} // namespace webrtc
107
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +0000108#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_