blob: 4ad9f7fbed90fc125c0e8fcd8d0a717214d699b0 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +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_AUDIO_PROCESSING_IMPL_H_
12#define MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <list>
kwiberg88788ad2016-02-19 07:04:49 -080015#include <memory>
Michael Graczyk86c6d332015-07-23 11:41:39 -070016#include <vector>
niklase@google.com470e71d2011-07-07 08:21:25 +000017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/audio_buffer.h"
19#include "modules/audio_processing/include/aec_dump.h"
20#include "modules/audio_processing/include/audio_processing.h"
21#include "modules/audio_processing/render_queue_item_verifier.h"
22#include "modules/audio_processing/rms_level.h"
23#include "rtc_base/criticalsection.h"
24#include "rtc_base/function_view.h"
25#include "rtc_base/gtest_prod_util.h"
26#include "rtc_base/ignore_wundef.h"
27#include "rtc_base/protobuf_utils.h"
28#include "rtc_base/swap_queue.h"
29#include "rtc_base/thread_annotations.h"
30#include "system_wrappers/include/file_wrapper.h"
peahdf3efa82015-11-28 12:35:15 -080031
niklase@google.com470e71d2011-07-07 08:21:25 +000032namespace webrtc {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000033
ekmeyerson60d9b332015-08-14 10:35:55 -070034class AudioConverter;
Alejandro Luebsf4022ff2016-07-01 17:19:09 -070035class NonlinearBeamformer;
Michael Graczykdfa36052015-03-25 16:37:27 -070036
niklase@google.com470e71d2011-07-07 08:21:25 +000037class AudioProcessingImpl : public AudioProcessing {
38 public:
peahdf3efa82015-11-28 12:35:15 -080039 // Methods forcing APM to run in a single-threaded manner.
40 // Acquires both the render and capture locks.
peah88ac8532016-09-12 16:47:25 -070041 explicit AudioProcessingImpl(const webrtc::Config& config);
Michael Graczykdfa36052015-03-25 16:37:27 -070042 // AudioProcessingImpl takes ownership of beamformer.
peah88ac8532016-09-12 16:47:25 -070043 AudioProcessingImpl(const webrtc::Config& config,
44 NonlinearBeamformer* beamformer);
kwiberg83ffe452016-08-29 14:46:07 -070045 ~AudioProcessingImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 int Initialize() override;
peahde65ddc2016-09-16 15:02:15 -070047 int Initialize(int capture_input_sample_rate_hz,
48 int capture_output_sample_rate_hz,
49 int render_sample_rate_hz,
50 ChannelLayout capture_input_layout,
51 ChannelLayout capture_output_layout,
52 ChannelLayout render_input_layout) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070053 int Initialize(const ProcessingConfig& processing_config) override;
peah88ac8532016-09-12 16:47:25 -070054 void ApplyConfig(const AudioProcessing::Config& config) override;
55 void SetExtraOptions(const webrtc::Config& config) override;
peahdf3efa82015-11-28 12:35:15 -080056 void UpdateHistogramsOnCallEnd() override;
aleloi868f32f2017-05-23 07:20:05 -070057 void AttachAecDump(std::unique_ptr<AecDump> aec_dump) override;
58 void DetachAecDump() override;
peahdf3efa82015-11-28 12:35:15 -080059
60 // Capture-side exclusive methods possibly running APM in a
61 // multi-threaded manner. Acquire the capture lock.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 int ProcessStream(AudioFrame* frame) override;
63 int ProcessStream(const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070064 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 int input_sample_rate_hz,
66 ChannelLayout input_layout,
67 int output_sample_rate_hz,
68 ChannelLayout output_layout,
69 float* const* dest) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070070 int ProcessStream(const float* const* src,
71 const StreamConfig& input_config,
72 const StreamConfig& output_config,
73 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -080074 void set_output_will_be_muted(bool muted) override;
75 int set_stream_delay_ms(int delay) override;
76 void set_delay_offset_ms(int offset) override;
77 int delay_offset_ms() const override;
78 void set_stream_key_pressed(bool key_pressed) override;
79
80 // Render-side exclusive methods possibly running APM in a
81 // multi-threaded manner. Acquire the render lock.
ekmeyerson60d9b332015-08-14 10:35:55 -070082 int ProcessReverseStream(AudioFrame* frame) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000083 int AnalyzeReverseStream(const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -070084 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000085 int sample_rate_hz,
86 ChannelLayout layout) override;
ekmeyerson60d9b332015-08-14 10:35:55 -070087 int ProcessReverseStream(const float* const* src,
peahde65ddc2016-09-16 15:02:15 -070088 const StreamConfig& input_config,
89 const StreamConfig& output_config,
ekmeyerson60d9b332015-08-14 10:35:55 -070090 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -080091
92 // Methods only accessed from APM submodules or
93 // from AudioProcessing tests in a single-threaded manner.
94 // Hence there is no need for locks in these.
95 int proc_sample_rate_hz() const override;
96 int proc_split_sample_rate_hz() const override;
Peter Kasting69558702016-01-12 16:26:35 -080097 size_t num_input_channels() const override;
98 size_t num_proc_channels() const override;
99 size_t num_output_channels() const override;
100 size_t num_reverse_channels() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000101 int stream_delay_ms() const override;
peahdf3efa82015-11-28 12:35:15 -0800102 bool was_stream_delay_set() const override
danilchap56359be2017-09-07 07:53:45 -0700103 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800104
ivoc3e9a5372016-10-28 07:55:33 -0700105 AudioProcessingStatistics GetStatistics() const override;
106
peahdf3efa82015-11-28 12:35:15 -0800107 // Methods returning pointers to APM submodules.
108 // No locks are aquired in those, as those locks
109 // would offer no protection (the submodules are
110 // created only once in a single-treaded manner
111 // during APM creation).
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000112 EchoCancellation* echo_cancellation() const override;
113 EchoControlMobile* echo_control_mobile() const override;
114 GainControl* gain_control() const override;
peah8271d042016-11-22 07:24:52 -0800115 // TODO(peah): Deprecate this API call.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000116 HighPassFilter* high_pass_filter() const override;
117 LevelEstimator* level_estimator() const override;
118 NoiseSuppression* noise_suppression() const override;
119 VoiceDetection* voice_detection() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
henrik.lundinadf06352017-04-05 05:48:24 -0700121 // TODO(peah): Remove MutateConfig once the new API allows that.
peah8271d042016-11-22 07:24:52 -0800122 void MutateConfig(rtc::FunctionView<void(AudioProcessing::Config*)> mutator);
henrik.lundinadf06352017-04-05 05:48:24 -0700123 AudioProcessing::Config GetConfig() const override;
peah8271d042016-11-22 07:24:52 -0800124
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000125 protected:
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000126 // Overridden in a mock.
peahdf3efa82015-11-28 12:35:15 -0800127 virtual int InitializeLocked()
danilchap56359be2017-09-07 07:53:45 -0700128 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000129
niklase@google.com470e71d2011-07-07 08:21:25 +0000130 private:
peahc19f3122016-10-07 14:54:10 -0700131 // TODO(peah): These friend classes should be removed as soon as the new
132 // parameter setting scheme allows.
133 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior);
134 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior);
135 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior);
peahdf3efa82015-11-28 12:35:15 -0800136 struct ApmPublicSubmodules;
137 struct ApmPrivateSubmodules;
138
peah8271d042016-11-22 07:24:52 -0800139 // Submodule interface implementations.
140 std::unique_ptr<HighPassFilter> high_pass_filter_impl_;
141
peah2ace3f92016-09-10 04:42:27 -0700142 class ApmSubmoduleStates {
143 public:
144 ApmSubmoduleStates();
145 // Updates the submodule state and returns true if it has changed.
peah8271d042016-11-22 07:24:52 -0800146 bool Update(bool low_cut_filter_enabled,
peah2ace3f92016-09-10 04:42:27 -0700147 bool echo_canceller_enabled,
148 bool mobile_echo_controller_enabled,
ivoc9f4a4a02016-10-28 05:39:16 -0700149 bool residual_echo_detector_enabled,
peah2ace3f92016-09-10 04:42:27 -0700150 bool noise_suppressor_enabled,
151 bool intelligibility_enhancer_enabled,
152 bool beamformer_enabled,
153 bool adaptive_gain_controller_enabled,
alessiob3ec96df2017-05-22 06:57:06 -0700154 bool gain_controller2_enabled,
peah2ace3f92016-09-10 04:42:27 -0700155 bool level_controller_enabled,
peahe0eae3c2016-12-14 01:16:23 -0800156 bool echo_canceller3_enabled,
peah2ace3f92016-09-10 04:42:27 -0700157 bool voice_activity_detector_enabled,
158 bool level_estimator_enabled,
159 bool transient_suppressor_enabled);
160 bool CaptureMultiBandSubModulesActive() const;
161 bool CaptureMultiBandProcessingActive() const;
peah23ac8b42017-05-23 05:33:56 -0700162 bool CaptureFullBandProcessingActive() const;
peah2ace3f92016-09-10 04:42:27 -0700163 bool RenderMultiBandSubModulesActive() const;
164 bool RenderMultiBandProcessingActive() const;
165
166 private:
peah8271d042016-11-22 07:24:52 -0800167 bool low_cut_filter_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700168 bool echo_canceller_enabled_ = false;
169 bool mobile_echo_controller_enabled_ = false;
ivoc9f4a4a02016-10-28 05:39:16 -0700170 bool residual_echo_detector_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700171 bool noise_suppressor_enabled_ = false;
172 bool intelligibility_enhancer_enabled_ = false;
173 bool beamformer_enabled_ = false;
174 bool adaptive_gain_controller_enabled_ = false;
alessiob3ec96df2017-05-22 06:57:06 -0700175 bool gain_controller2_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700176 bool level_controller_enabled_ = false;
peahe0eae3c2016-12-14 01:16:23 -0800177 bool echo_canceller3_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700178 bool level_estimator_enabled_ = false;
179 bool voice_activity_detector_enabled_ = false;
180 bool transient_suppressor_enabled_ = false;
181 bool first_update_ = true;
182 };
183
peahdf3efa82015-11-28 12:35:15 -0800184 // Method for modifying the formats struct that are called from both
185 // the render and capture threads. The check for whether modifications
186 // are needed is done while holding the render lock only, thereby avoiding
187 // that the capture thread blocks the render thread.
188 // The struct is modified in a single-threaded manner by holding both the
189 // render and capture locks.
peah2ace3f92016-09-10 04:42:27 -0700190 int MaybeInitialize(const ProcessingConfig& config, bool force_initialization)
danilchap56359be2017-09-07 07:53:45 -0700191 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahdf3efa82015-11-28 12:35:15 -0800192
193 int MaybeInitializeRender(const ProcessingConfig& processing_config)
danilchap56359be2017-09-07 07:53:45 -0700194 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahdf3efa82015-11-28 12:35:15 -0800195
peah2ace3f92016-09-10 04:42:27 -0700196 int MaybeInitializeCapture(const ProcessingConfig& processing_config,
197 bool force_initialization)
danilchap56359be2017-09-07 07:53:45 -0700198 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahdf3efa82015-11-28 12:35:15 -0800199
peah2ace3f92016-09-10 04:42:27 -0700200 // Method for updating the state keeping track of the active submodules.
201 // Returns a bool indicating whether the state has changed.
danilchap56359be2017-09-07 07:53:45 -0700202 bool UpdateActiveSubmoduleStates()
203 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800204
205 // Methods requiring APM running in a single-threaded manner.
206 // Are called with both the render and capture locks already
207 // acquired.
peahdf3efa82015-11-28 12:35:15 -0800208 void InitializeTransient()
danilchap56359be2017-09-07 07:53:45 -0700209 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800210 void InitializeBeamformer()
danilchap56359be2017-09-07 07:53:45 -0700211 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800212 void InitializeIntelligibility()
danilchap56359be2017-09-07 07:53:45 -0700213 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700214 int InitializeLocked(const ProcessingConfig& config)
danilchap56359be2017-09-07 07:53:45 -0700215 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
216 void InitializeLevelController() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
ivoc9f4a4a02016-10-28 05:39:16 -0700217 void InitializeResidualEchoDetector()
danilchap56359be2017-09-07 07:53:45 -0700218 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
219 void InitializeLowCutFilter() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
220 void InitializeEchoCanceller3() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
alessiob3ec96df2017-05-22 06:57:06 -0700221 void InitializeGainController2();
peahdf3efa82015-11-28 12:35:15 -0800222
peah764e3642016-10-22 05:04:30 -0700223 void EmptyQueuedRenderAudio();
224 void AllocateRenderQueue()
danilchap56359be2017-09-07 07:53:45 -0700225 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peah9e6a2902017-05-15 07:19:21 -0700226 void QueueBandedRenderAudio(AudioBuffer* audio)
danilchap56359be2017-09-07 07:53:45 -0700227 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peah9e6a2902017-05-15 07:19:21 -0700228 void QueueNonbandedRenderAudio(AudioBuffer* audio)
danilchap56359be2017-09-07 07:53:45 -0700229 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peah764e3642016-10-22 05:04:30 -0700230
peahdf3efa82015-11-28 12:35:15 -0800231 // Capture-side exclusive methods possibly running APM in a multi-threaded
232 // manner that are called with the render lock already acquired.
danilchap56359be2017-09-07 07:53:45 -0700233 int ProcessCaptureStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
234 void MaybeUpdateHistograms() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800235
236 // Render-side exclusive methods possibly running APM in a multi-threaded
237 // manner that are called with the render lock already acquired.
ekmeyerson60d9b332015-08-14 10:35:55 -0700238 // TODO(ekm): Remove once all clients updated to new interface.
peahdf3efa82015-11-28 12:35:15 -0800239 int AnalyzeReverseStreamLocked(const float* const* src,
240 const StreamConfig& input_config,
241 const StreamConfig& output_config)
danilchap56359be2017-09-07 07:53:45 -0700242 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
243 int ProcessRenderStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000244
aleloi868f32f2017-05-23 07:20:05 -0700245 // Collects configuration settings from public and private
246 // submodules to be saved as an audioproc::Config message on the
247 // AecDump if it is attached. If not |forced|, only writes the current
248 // config if it is different from the last saved one; if |forced|,
249 // writes the config regardless of the last saved.
250 void WriteAecDumpConfigMessage(bool forced)
danilchap56359be2017-09-07 07:53:45 -0700251 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700252
253 // Notifies attached AecDump of current configuration and capture data.
254 void RecordUnprocessedCaptureStream(const float* const* capture_stream)
danilchap56359be2017-09-07 07:53:45 -0700255 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700256
257 void RecordUnprocessedCaptureStream(const AudioFrame& capture_frame)
danilchap56359be2017-09-07 07:53:45 -0700258 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700259
260 // Notifies attached AecDump of current configuration and
261 // processed capture data and issues a capture stream recording
262 // request.
263 void RecordProcessedCaptureStream(
264 const float* const* processed_capture_stream)
danilchap56359be2017-09-07 07:53:45 -0700265 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700266
267 void RecordProcessedCaptureStream(const AudioFrame& processed_capture_frame)
danilchap56359be2017-09-07 07:53:45 -0700268 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700269
270 // Notifies attached AecDump about current state (delay, drift, etc).
danilchap56359be2017-09-07 07:53:45 -0700271 void RecordAudioProcessingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700272
aleloi868f32f2017-05-23 07:20:05 -0700273 // AecDump instance used for optionally logging APM config, input
274 // and output to file in the AEC-dump format defined in debug.proto.
275 std::unique_ptr<AecDump> aec_dump_;
276
277 // Hold the last config written with AecDump for avoiding writing
278 // the same config twice.
danilchap56359be2017-09-07 07:53:45 -0700279 InternalAPMConfig apm_config_for_aec_dump_ RTC_GUARDED_BY(crit_capture_);
aleloi868f32f2017-05-23 07:20:05 -0700280
peahdf3efa82015-11-28 12:35:15 -0800281 // Critical sections.
danilchap56359be2017-09-07 07:53:45 -0700282 rtc::CriticalSection crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_);
pbos5ad935c2016-01-25 03:52:44 -0800283 rtc::CriticalSection crit_capture_;
peahdf3efa82015-11-28 12:35:15 -0800284
peahc19f3122016-10-07 14:54:10 -0700285 // Struct containing the Config specifying the behavior of APM.
286 AudioProcessing::Config config_;
287
peah2ace3f92016-09-10 04:42:27 -0700288 // Class containing information about what submodules are active.
289 ApmSubmoduleStates submodule_states_;
290
peahdf3efa82015-11-28 12:35:15 -0800291 // Structs containing the pointers to the submodules.
kwiberg88788ad2016-02-19 07:04:49 -0800292 std::unique_ptr<ApmPublicSubmodules> public_submodules_;
ivoc9f4a4a02016-10-28 05:39:16 -0700293 std::unique_ptr<ApmPrivateSubmodules> private_submodules_;
peahdf3efa82015-11-28 12:35:15 -0800294
peah192164e2015-11-17 02:16:45 -0800295 // State that is written to while holding both the render and capture locks
peahdf3efa82015-11-28 12:35:15 -0800296 // but can be read without any lock being held.
297 // As this is only accessed internally of APM, and all internal methods in APM
298 // either are holding the render or capture locks, this construct is safe as
299 // it is not possible to read the variables while writing them.
300 struct ApmFormatState {
301 ApmFormatState()
peah192164e2015-11-17 02:16:45 -0800302 : // Format of processing streams at input/output call sites.
peahdf3efa82015-11-28 12:35:15 -0800303 api_format({{{kSampleRate16kHz, 1, false},
304 {kSampleRate16kHz, 1, false},
305 {kSampleRate16kHz, 1, false},
306 {kSampleRate16kHz, 1, false}}}),
peahde65ddc2016-09-16 15:02:15 -0700307 render_processing_format(kSampleRate16kHz, 1) {}
peahdf3efa82015-11-28 12:35:15 -0800308 ProcessingConfig api_format;
peahde65ddc2016-09-16 15:02:15 -0700309 StreamConfig render_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800310 } formats_;
Michael Graczyk86c6d332015-07-23 11:41:39 -0700311
peahdf3efa82015-11-28 12:35:15 -0800312 // APM constants.
313 const struct ApmConstants {
henrik.lundinbd681b92016-12-05 09:08:42 -0800314 ApmConstants(int agc_startup_min_volume,
315 int agc_clipped_level_min,
316 bool use_experimental_agc)
peahdf3efa82015-11-28 12:35:15 -0800317 : // Format of processing streams at input/output call sites.
318 agc_startup_min_volume(agc_startup_min_volume),
henrik.lundinbd681b92016-12-05 09:08:42 -0800319 agc_clipped_level_min(agc_clipped_level_min),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700320 use_experimental_agc(use_experimental_agc) {}
peahdf3efa82015-11-28 12:35:15 -0800321 int agc_startup_min_volume;
henrik.lundinbd681b92016-12-05 09:08:42 -0800322 int agc_clipped_level_min;
peahbe615622016-02-13 16:40:47 -0800323 bool use_experimental_agc;
peahdf3efa82015-11-28 12:35:15 -0800324 } constants_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000325
peahdf3efa82015-11-28 12:35:15 -0800326 struct ApmCaptureState {
aluebs2a346882016-01-11 18:04:30 -0800327 ApmCaptureState(bool transient_suppressor_enabled,
aluebs2a346882016-01-11 18:04:30 -0800328 const std::vector<Point>& array_geometry,
kwiberg83ffe452016-08-29 14:46:07 -0700329 SphericalPointf target_direction);
330 ~ApmCaptureState();
peahdf3efa82015-11-28 12:35:15 -0800331 int aec_system_delay_jumps;
332 int delay_offset_ms;
333 bool was_stream_delay_set;
334 int last_stream_delay_ms;
335 int last_aec_system_delay_ms;
336 int stream_delay_jumps;
337 bool output_will_be_muted;
338 bool key_pressed;
339 bool transient_suppressor_enabled;
aluebs2a346882016-01-11 18:04:30 -0800340 std::vector<Point> array_geometry;
341 SphericalPointf target_direction;
kwiberg88788ad2016-02-19 07:04:49 -0800342 std::unique_ptr<AudioBuffer> capture_audio;
peahde65ddc2016-09-16 15:02:15 -0700343 // Only the rate and samples fields of capture_processing_format_ are used
344 // because the capture processing number of channels is mutable and is
345 // tracked by the capture_audio_.
346 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800347 int split_rate;
peah67995532017-04-10 14:12:41 -0700348 bool echo_path_gain_change;
danilchap56359be2017-09-07 07:53:45 -0700349 } capture_ RTC_GUARDED_BY(crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000350
peahdf3efa82015-11-28 12:35:15 -0800351 struct ApmCaptureNonLockedState {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700352 ApmCaptureNonLockedState(bool beamformer_enabled,
peah88ac8532016-09-12 16:47:25 -0700353 bool intelligibility_enabled)
peahde65ddc2016-09-16 15:02:15 -0700354 : capture_processing_format(kSampleRate16kHz),
peahdf3efa82015-11-28 12:35:15 -0800355 split_rate(kSampleRate16kHz),
aluebsb2328d12016-01-11 20:32:29 -0800356 stream_delay_ms(0),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700357 beamformer_enabled(beamformer_enabled),
peah88ac8532016-09-12 16:47:25 -0700358 intelligibility_enabled(intelligibility_enabled) {}
peahde65ddc2016-09-16 15:02:15 -0700359 // Only the rate and samples fields of capture_processing_format_ are used
360 // because the forward processing number of channels is mutable and is
361 // tracked by the capture_audio_.
362 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800363 int split_rate;
364 int stream_delay_ms;
aluebsb2328d12016-01-11 20:32:29 -0800365 bool beamformer_enabled;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700366 bool intelligibility_enabled;
peah88ac8532016-09-12 16:47:25 -0700367 bool level_controller_enabled = false;
peahe0eae3c2016-12-14 01:16:23 -0800368 bool echo_canceller3_enabled = false;
alessiob3ec96df2017-05-22 06:57:06 -0700369 bool gain_controller2_enabled = false;
peahdf3efa82015-11-28 12:35:15 -0800370 } capture_nonlocked_;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000371
peahdf3efa82015-11-28 12:35:15 -0800372 struct ApmRenderState {
kwiberg83ffe452016-08-29 14:46:07 -0700373 ApmRenderState();
374 ~ApmRenderState();
kwiberg88788ad2016-02-19 07:04:49 -0800375 std::unique_ptr<AudioConverter> render_converter;
376 std::unique_ptr<AudioBuffer> render_audio;
danilchap56359be2017-09-07 07:53:45 -0700377 } render_ RTC_GUARDED_BY(crit_render_);
peah764e3642016-10-22 05:04:30 -0700378
danilchap56359be2017-09-07 07:53:45 -0700379 size_t aec_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
380 RTC_GUARDED_BY(crit_capture_) = 0;
381 std::vector<float> aec_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
382 std::vector<float> aec_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
peaha0624602016-10-25 04:45:24 -0700383
danilchap56359be2017-09-07 07:53:45 -0700384 size_t aecm_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
385 RTC_GUARDED_BY(crit_capture_) = 0;
386 std::vector<int16_t> aecm_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
387 std::vector<int16_t> aecm_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
peah701d6282016-10-25 05:42:20 -0700388
danilchap56359be2017-09-07 07:53:45 -0700389 size_t agc_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
390 RTC_GUARDED_BY(crit_capture_) = 0;
391 std::vector<int16_t> agc_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
392 std::vector<int16_t> agc_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
peah764e3642016-10-22 05:04:30 -0700393
danilchap56359be2017-09-07 07:53:45 -0700394 size_t red_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
395 RTC_GUARDED_BY(crit_capture_) = 0;
396 std::vector<float> red_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
397 std::vector<float> red_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
ivoc9f4a4a02016-10-28 05:39:16 -0700398
danilchap56359be2017-09-07 07:53:45 -0700399 RmsLevel capture_input_rms_ RTC_GUARDED_BY(crit_capture_);
400 RmsLevel capture_output_rms_ RTC_GUARDED_BY(crit_capture_);
401 int capture_rms_interval_counter_ RTC_GUARDED_BY(crit_capture_) = 0;
henrik.lundin290d43a2016-11-29 08:09:09 -0800402
peah764e3642016-10-22 05:04:30 -0700403 // Lock protection not needed.
404 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
peah701d6282016-10-25 05:42:20 -0700405 aec_render_signal_queue_;
peaha0624602016-10-25 04:45:24 -0700406 std::unique_ptr<
407 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
peah701d6282016-10-25 05:42:20 -0700408 aecm_render_signal_queue_;
409 std::unique_ptr<
410 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
411 agc_render_signal_queue_;
ivoc9f4a4a02016-10-28 05:39:16 -0700412 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
413 red_render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000415
niklase@google.com470e71d2011-07-07 08:21:25 +0000416} // namespace webrtc
417
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200418#endif // MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_