blob: 325d1be564dec8fc25148f959c406fc3a90b781f [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
pbos@webrtc.org788acd12014-12-15 09:41:24 +000011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
12#define WEBRTC_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
peahdf3efa82015-11-28 12:35:15 -080018#include "webrtc/modules/audio_processing/audio_buffer.h"
aleloi868f32f2017-05-23 07:20:05 -070019#include "webrtc/modules/audio_processing/include/aec_dump.h"
Michael Graczykdfa36052015-03-25 16:37:27 -070020#include "webrtc/modules/audio_processing/include/audio_processing.h"
peah764e3642016-10-22 05:04:30 -070021#include "webrtc/modules/audio_processing/render_queue_item_verifier.h"
henrik.lundin290d43a2016-11-29 08:09:09 -080022#include "webrtc/modules/audio_processing/rms_level.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020023#include "webrtc/rtc_base/criticalsection.h"
24#include "webrtc/rtc_base/function_view.h"
25#include "webrtc/rtc_base/gtest_prod_util.h"
26#include "webrtc/rtc_base/ignore_wundef.h"
27#include "webrtc/rtc_base/protobuf_utils.h"
28#include "webrtc/rtc_base/swap_queue.h"
29#include "webrtc/rtc_base/thread_annotations.h"
peahdf3efa82015-11-28 12:35:15 -080030#include "webrtc/system_wrappers/include/file_wrapper.h"
31
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
103 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
104
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()
128 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)
peahdf3efa82015-11-28 12:35:15 -0800191 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
192
193 int MaybeInitializeRender(const ProcessingConfig& processing_config)
194 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
195
peah2ace3f92016-09-10 04:42:27 -0700196 int MaybeInitializeCapture(const ProcessingConfig& processing_config,
197 bool force_initialization)
peahdf3efa82015-11-28 12:35:15 -0800198 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
199
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.
202 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800203
204 // Methods requiring APM running in a single-threaded manner.
205 // Are called with both the render and capture locks already
206 // acquired.
peahdf3efa82015-11-28 12:35:15 -0800207 void InitializeTransient()
208 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
209 void InitializeBeamformer()
210 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
211 void InitializeIntelligibility()
212 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700213 int InitializeLocked(const ProcessingConfig& config)
peahdf3efa82015-11-28 12:35:15 -0800214 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peahca4cac72016-06-29 15:26:12 -0700215 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
ivoc9f4a4a02016-10-28 05:39:16 -0700216 void InitializeResidualEchoDetector()
217 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peah8271d042016-11-22 07:24:52 -0800218 void InitializeLowCutFilter() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahe0eae3c2016-12-14 01:16:23 -0800219 void InitializeEchoCanceller3() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
alessiob3ec96df2017-05-22 06:57:06 -0700220 void InitializeGainController2();
peahdf3efa82015-11-28 12:35:15 -0800221
peah764e3642016-10-22 05:04:30 -0700222 void EmptyQueuedRenderAudio();
223 void AllocateRenderQueue()
224 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peah9e6a2902017-05-15 07:19:21 -0700225 void QueueBandedRenderAudio(AudioBuffer* audio)
226 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
227 void QueueNonbandedRenderAudio(AudioBuffer* audio)
peah764e3642016-10-22 05:04:30 -0700228 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
229
peahdf3efa82015-11-28 12:35:15 -0800230 // Capture-side exclusive methods possibly running APM in a multi-threaded
231 // manner that are called with the render lock already acquired.
peahde65ddc2016-09-16 15:02:15 -0700232 int ProcessCaptureStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800233 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
234
235 // Render-side exclusive methods possibly running APM in a multi-threaded
236 // manner that are called with the render lock already acquired.
ekmeyerson60d9b332015-08-14 10:35:55 -0700237 // TODO(ekm): Remove once all clients updated to new interface.
peahdf3efa82015-11-28 12:35:15 -0800238 int AnalyzeReverseStreamLocked(const float* const* src,
239 const StreamConfig& input_config,
240 const StreamConfig& output_config)
241 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahde65ddc2016-09-16 15:02:15 -0700242 int ProcessRenderStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000243
aleloi868f32f2017-05-23 07:20:05 -0700244 // Collects configuration settings from public and private
245 // submodules to be saved as an audioproc::Config message on the
246 // AecDump if it is attached. If not |forced|, only writes the current
247 // config if it is different from the last saved one; if |forced|,
248 // writes the config regardless of the last saved.
249 void WriteAecDumpConfigMessage(bool forced)
250 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
251
252 // Notifies attached AecDump of current configuration and capture data.
253 void RecordUnprocessedCaptureStream(const float* const* capture_stream)
254 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
255
256 void RecordUnprocessedCaptureStream(const AudioFrame& capture_frame)
257 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
258
259 // Notifies attached AecDump of current configuration and
260 // processed capture data and issues a capture stream recording
261 // request.
262 void RecordProcessedCaptureStream(
263 const float* const* processed_capture_stream)
264 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
265
266 void RecordProcessedCaptureStream(const AudioFrame& processed_capture_frame)
267 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
268
269 // Notifies attached AecDump about current state (delay, drift, etc).
270 void RecordAudioProcessingState() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
271
aleloi868f32f2017-05-23 07:20:05 -0700272 // AecDump instance used for optionally logging APM config, input
273 // and output to file in the AEC-dump format defined in debug.proto.
274 std::unique_ptr<AecDump> aec_dump_;
275
276 // Hold the last config written with AecDump for avoiding writing
277 // the same config twice.
278 InternalAPMConfig apm_config_for_aec_dump_ GUARDED_BY(crit_capture_);
279
peahdf3efa82015-11-28 12:35:15 -0800280 // Critical sections.
pbos5ad935c2016-01-25 03:52:44 -0800281 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_);
282 rtc::CriticalSection crit_capture_;
peahdf3efa82015-11-28 12:35:15 -0800283
peahc19f3122016-10-07 14:54:10 -0700284 // Struct containing the Config specifying the behavior of APM.
285 AudioProcessing::Config config_;
286
peah2ace3f92016-09-10 04:42:27 -0700287 // Class containing information about what submodules are active.
288 ApmSubmoduleStates submodule_states_;
289
peahdf3efa82015-11-28 12:35:15 -0800290 // Structs containing the pointers to the submodules.
kwiberg88788ad2016-02-19 07:04:49 -0800291 std::unique_ptr<ApmPublicSubmodules> public_submodules_;
ivoc9f4a4a02016-10-28 05:39:16 -0700292 std::unique_ptr<ApmPrivateSubmodules> private_submodules_;
peahdf3efa82015-11-28 12:35:15 -0800293
peah192164e2015-11-17 02:16:45 -0800294 // State that is written to while holding both the render and capture locks
peahdf3efa82015-11-28 12:35:15 -0800295 // but can be read without any lock being held.
296 // As this is only accessed internally of APM, and all internal methods in APM
297 // either are holding the render or capture locks, this construct is safe as
298 // it is not possible to read the variables while writing them.
299 struct ApmFormatState {
300 ApmFormatState()
peah192164e2015-11-17 02:16:45 -0800301 : // Format of processing streams at input/output call sites.
peahdf3efa82015-11-28 12:35:15 -0800302 api_format({{{kSampleRate16kHz, 1, false},
303 {kSampleRate16kHz, 1, false},
304 {kSampleRate16kHz, 1, false},
305 {kSampleRate16kHz, 1, false}}}),
peahde65ddc2016-09-16 15:02:15 -0700306 render_processing_format(kSampleRate16kHz, 1) {}
peahdf3efa82015-11-28 12:35:15 -0800307 ProcessingConfig api_format;
peahde65ddc2016-09-16 15:02:15 -0700308 StreamConfig render_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800309 } formats_;
Michael Graczyk86c6d332015-07-23 11:41:39 -0700310
peahdf3efa82015-11-28 12:35:15 -0800311 // APM constants.
312 const struct ApmConstants {
henrik.lundinbd681b92016-12-05 09:08:42 -0800313 ApmConstants(int agc_startup_min_volume,
314 int agc_clipped_level_min,
315 bool use_experimental_agc)
peahdf3efa82015-11-28 12:35:15 -0800316 : // Format of processing streams at input/output call sites.
317 agc_startup_min_volume(agc_startup_min_volume),
henrik.lundinbd681b92016-12-05 09:08:42 -0800318 agc_clipped_level_min(agc_clipped_level_min),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700319 use_experimental_agc(use_experimental_agc) {}
peahdf3efa82015-11-28 12:35:15 -0800320 int agc_startup_min_volume;
henrik.lundinbd681b92016-12-05 09:08:42 -0800321 int agc_clipped_level_min;
peahbe615622016-02-13 16:40:47 -0800322 bool use_experimental_agc;
peahdf3efa82015-11-28 12:35:15 -0800323 } constants_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000324
peahdf3efa82015-11-28 12:35:15 -0800325 struct ApmCaptureState {
aluebs2a346882016-01-11 18:04:30 -0800326 ApmCaptureState(bool transient_suppressor_enabled,
aluebs2a346882016-01-11 18:04:30 -0800327 const std::vector<Point>& array_geometry,
kwiberg83ffe452016-08-29 14:46:07 -0700328 SphericalPointf target_direction);
329 ~ApmCaptureState();
peahdf3efa82015-11-28 12:35:15 -0800330 int aec_system_delay_jumps;
331 int delay_offset_ms;
332 bool was_stream_delay_set;
333 int last_stream_delay_ms;
334 int last_aec_system_delay_ms;
335 int stream_delay_jumps;
336 bool output_will_be_muted;
337 bool key_pressed;
338 bool transient_suppressor_enabled;
aluebs2a346882016-01-11 18:04:30 -0800339 std::vector<Point> array_geometry;
340 SphericalPointf target_direction;
kwiberg88788ad2016-02-19 07:04:49 -0800341 std::unique_ptr<AudioBuffer> capture_audio;
peahde65ddc2016-09-16 15:02:15 -0700342 // Only the rate and samples fields of capture_processing_format_ are used
343 // because the capture processing number of channels is mutable and is
344 // tracked by the capture_audio_.
345 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800346 int split_rate;
peah67995532017-04-10 14:12:41 -0700347 bool echo_path_gain_change;
peahdf3efa82015-11-28 12:35:15 -0800348 } capture_ GUARDED_BY(crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000349
peahdf3efa82015-11-28 12:35:15 -0800350 struct ApmCaptureNonLockedState {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700351 ApmCaptureNonLockedState(bool beamformer_enabled,
peah88ac8532016-09-12 16:47:25 -0700352 bool intelligibility_enabled)
peahde65ddc2016-09-16 15:02:15 -0700353 : capture_processing_format(kSampleRate16kHz),
peahdf3efa82015-11-28 12:35:15 -0800354 split_rate(kSampleRate16kHz),
aluebsb2328d12016-01-11 20:32:29 -0800355 stream_delay_ms(0),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700356 beamformer_enabled(beamformer_enabled),
peah88ac8532016-09-12 16:47:25 -0700357 intelligibility_enabled(intelligibility_enabled) {}
peahde65ddc2016-09-16 15:02:15 -0700358 // Only the rate and samples fields of capture_processing_format_ are used
359 // because the forward processing number of channels is mutable and is
360 // tracked by the capture_audio_.
361 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800362 int split_rate;
363 int stream_delay_ms;
aluebsb2328d12016-01-11 20:32:29 -0800364 bool beamformer_enabled;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700365 bool intelligibility_enabled;
peah88ac8532016-09-12 16:47:25 -0700366 bool level_controller_enabled = false;
peahe0eae3c2016-12-14 01:16:23 -0800367 bool echo_canceller3_enabled = false;
alessiob3ec96df2017-05-22 06:57:06 -0700368 bool gain_controller2_enabled = false;
peahdf3efa82015-11-28 12:35:15 -0800369 } capture_nonlocked_;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000370
peahdf3efa82015-11-28 12:35:15 -0800371 struct ApmRenderState {
kwiberg83ffe452016-08-29 14:46:07 -0700372 ApmRenderState();
373 ~ApmRenderState();
kwiberg88788ad2016-02-19 07:04:49 -0800374 std::unique_ptr<AudioConverter> render_converter;
375 std::unique_ptr<AudioBuffer> render_audio;
peahdf3efa82015-11-28 12:35:15 -0800376 } render_ GUARDED_BY(crit_render_);
peah764e3642016-10-22 05:04:30 -0700377
peah701d6282016-10-25 05:42:20 -0700378 size_t aec_render_queue_element_max_size_ GUARDED_BY(crit_render_)
peah764e3642016-10-22 05:04:30 -0700379 GUARDED_BY(crit_capture_) = 0;
peah701d6282016-10-25 05:42:20 -0700380 std::vector<float> aec_render_queue_buffer_ GUARDED_BY(crit_render_);
381 std::vector<float> aec_capture_queue_buffer_ GUARDED_BY(crit_capture_);
peaha0624602016-10-25 04:45:24 -0700382
peah701d6282016-10-25 05:42:20 -0700383 size_t aecm_render_queue_element_max_size_ GUARDED_BY(crit_render_)
peaha0624602016-10-25 04:45:24 -0700384 GUARDED_BY(crit_capture_) = 0;
peah701d6282016-10-25 05:42:20 -0700385 std::vector<int16_t> aecm_render_queue_buffer_ GUARDED_BY(crit_render_);
386 std::vector<int16_t> aecm_capture_queue_buffer_ GUARDED_BY(crit_capture_);
387
388 size_t agc_render_queue_element_max_size_ GUARDED_BY(crit_render_)
389 GUARDED_BY(crit_capture_) = 0;
390 std::vector<int16_t> agc_render_queue_buffer_ GUARDED_BY(crit_render_);
391 std::vector<int16_t> agc_capture_queue_buffer_ GUARDED_BY(crit_capture_);
peah764e3642016-10-22 05:04:30 -0700392
ivoc9f4a4a02016-10-28 05:39:16 -0700393 size_t red_render_queue_element_max_size_ GUARDED_BY(crit_render_)
394 GUARDED_BY(crit_capture_) = 0;
395 std::vector<float> red_render_queue_buffer_ GUARDED_BY(crit_render_);
396 std::vector<float> red_capture_queue_buffer_ GUARDED_BY(crit_capture_);
397
peah1b08dc32016-12-20 13:45:58 -0800398 RmsLevel capture_input_rms_ GUARDED_BY(crit_capture_);
399 RmsLevel capture_output_rms_ GUARDED_BY(crit_capture_);
400 int capture_rms_interval_counter_ GUARDED_BY(crit_capture_) = 0;
henrik.lundin290d43a2016-11-29 08:09:09 -0800401
peah764e3642016-10-22 05:04:30 -0700402 // Lock protection not needed.
403 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
peah701d6282016-10-25 05:42:20 -0700404 aec_render_signal_queue_;
peaha0624602016-10-25 04:45:24 -0700405 std::unique_ptr<
406 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
peah701d6282016-10-25 05:42:20 -0700407 aecm_render_signal_queue_;
408 std::unique_ptr<
409 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
410 agc_render_signal_queue_;
ivoc9f4a4a02016-10-28 05:39:16 -0700411 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
412 red_render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000413};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000414
niklase@google.com470e71d2011-07-07 08:21:25 +0000415} // namespace webrtc
416
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000417#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_