blob: d171715a96412642e98df7dc68bef60d4105f621 [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>
ajm@google.com808e0e02011-08-03 21:08:51 +000016#include <string>
Michael Graczyk86c6d332015-07-23 11:41:39 -070017#include <vector>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
peahdf3efa82015-11-28 12:35:15 -080019#include "webrtc/base/criticalsection.h"
peah8271d042016-11-22 07:24:52 -080020#include "webrtc/base/function_view.h"
peahc19f3122016-10-07 14:54:10 -070021#include "webrtc/base/gtest_prod_util.h"
kwiberg77eab702016-09-28 17:42:01 -070022#include "webrtc/base/ignore_wundef.h"
peah764e3642016-10-22 05:04:30 -070023#include "webrtc/base/swap_queue.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000024#include "webrtc/base/thread_annotations.h"
peahdf3efa82015-11-28 12:35:15 -080025#include "webrtc/modules/audio_processing/audio_buffer.h"
Michael Graczykdfa36052015-03-25 16:37:27 -070026#include "webrtc/modules/audio_processing/include/audio_processing.h"
peah764e3642016-10-22 05:04:30 -070027#include "webrtc/modules/audio_processing/render_queue_item_verifier.h"
peahdf3efa82015-11-28 12:35:15 -080028#include "webrtc/system_wrappers/include/file_wrapper.h"
29
30#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
31// Files generated at build-time by the protobuf compiler.
kwiberg77eab702016-09-28 17:42:01 -070032RTC_PUSH_IGNORING_WUNDEF()
peahdf3efa82015-11-28 12:35:15 -080033#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
34#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
35#else
kjellander78ddd732016-02-09 08:13:06 -080036#include "webrtc/modules/audio_processing/debug.pb.h"
peahdf3efa82015-11-28 12:35:15 -080037#endif
kwiberg77eab702016-09-28 17:42:01 -070038RTC_POP_IGNORING_WUNDEF()
peahdf3efa82015-11-28 12:35:15 -080039#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +000040
41namespace webrtc {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000042
pbos@webrtc.org788acd12014-12-15 09:41:24 +000043class AgcManagerDirect;
ekmeyerson60d9b332015-08-14 10:35:55 -070044class AudioConverter;
Michael Graczykdfa36052015-03-25 16:37:27 -070045
Alejandro Luebsf4022ff2016-07-01 17:19:09 -070046class NonlinearBeamformer;
Michael Graczykdfa36052015-03-25 16:37:27 -070047
niklase@google.com470e71d2011-07-07 08:21:25 +000048class AudioProcessingImpl : public AudioProcessing {
49 public:
peahdf3efa82015-11-28 12:35:15 -080050 // Methods forcing APM to run in a single-threaded manner.
51 // Acquires both the render and capture locks.
peah88ac8532016-09-12 16:47:25 -070052 explicit AudioProcessingImpl(const webrtc::Config& config);
Michael Graczykdfa36052015-03-25 16:37:27 -070053 // AudioProcessingImpl takes ownership of beamformer.
peah88ac8532016-09-12 16:47:25 -070054 AudioProcessingImpl(const webrtc::Config& config,
55 NonlinearBeamformer* beamformer);
kwiberg83ffe452016-08-29 14:46:07 -070056 ~AudioProcessingImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 int Initialize() override;
peahde65ddc2016-09-16 15:02:15 -070058 int Initialize(int capture_input_sample_rate_hz,
59 int capture_output_sample_rate_hz,
60 int render_sample_rate_hz,
61 ChannelLayout capture_input_layout,
62 ChannelLayout capture_output_layout,
63 ChannelLayout render_input_layout) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070064 int Initialize(const ProcessingConfig& processing_config) override;
peah88ac8532016-09-12 16:47:25 -070065 void ApplyConfig(const AudioProcessing::Config& config) override;
66 void SetExtraOptions(const webrtc::Config& config) override;
peahdf3efa82015-11-28 12:35:15 -080067 void UpdateHistogramsOnCallEnd() override;
ivocd66b44d2016-01-15 03:06:36 -080068 int StartDebugRecording(const char filename[kMaxFilenameSize],
69 int64_t max_log_size_bytes) override;
70 int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override;
peah73a28ee2016-10-12 03:01:49 -070071 int StartDebugRecording(FILE* handle) override;
peahdf3efa82015-11-28 12:35:15 -080072 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override;
73 int StopDebugRecording() override;
74
75 // Capture-side exclusive methods possibly running APM in a
76 // multi-threaded manner. Acquire the capture lock.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000077 int ProcessStream(AudioFrame* frame) override;
78 int ProcessStream(const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070079 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000080 int input_sample_rate_hz,
81 ChannelLayout input_layout,
82 int output_sample_rate_hz,
83 ChannelLayout output_layout,
84 float* const* dest) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070085 int ProcessStream(const float* const* src,
86 const StreamConfig& input_config,
87 const StreamConfig& output_config,
88 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -080089 void set_output_will_be_muted(bool muted) override;
90 int set_stream_delay_ms(int delay) override;
91 void set_delay_offset_ms(int offset) override;
92 int delay_offset_ms() const override;
93 void set_stream_key_pressed(bool key_pressed) override;
94
95 // Render-side exclusive methods possibly running APM in a
96 // multi-threaded manner. Acquire the render lock.
ekmeyerson60d9b332015-08-14 10:35:55 -070097 int ProcessReverseStream(AudioFrame* frame) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000098 int AnalyzeReverseStream(const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -070099 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000100 int sample_rate_hz,
101 ChannelLayout layout) override;
ekmeyerson60d9b332015-08-14 10:35:55 -0700102 int ProcessReverseStream(const float* const* src,
peahde65ddc2016-09-16 15:02:15 -0700103 const StreamConfig& input_config,
104 const StreamConfig& output_config,
ekmeyerson60d9b332015-08-14 10:35:55 -0700105 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -0800106
107 // Methods only accessed from APM submodules or
108 // from AudioProcessing tests in a single-threaded manner.
109 // Hence there is no need for locks in these.
110 int proc_sample_rate_hz() const override;
111 int proc_split_sample_rate_hz() const override;
Peter Kasting69558702016-01-12 16:26:35 -0800112 size_t num_input_channels() const override;
113 size_t num_proc_channels() const override;
114 size_t num_output_channels() const override;
115 size_t num_reverse_channels() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000116 int stream_delay_ms() const override;
peahdf3efa82015-11-28 12:35:15 -0800117 bool was_stream_delay_set() const override
118 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
119
ivoc3e9a5372016-10-28 07:55:33 -0700120 AudioProcessingStatistics GetStatistics() const override;
121
peahdf3efa82015-11-28 12:35:15 -0800122 // Methods returning pointers to APM submodules.
123 // No locks are aquired in those, as those locks
124 // would offer no protection (the submodules are
125 // created only once in a single-treaded manner
126 // during APM creation).
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000127 EchoCancellation* echo_cancellation() const override;
128 EchoControlMobile* echo_control_mobile() const override;
129 GainControl* gain_control() const override;
peah8271d042016-11-22 07:24:52 -0800130 // TODO(peah): Deprecate this API call.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000131 HighPassFilter* high_pass_filter() const override;
132 LevelEstimator* level_estimator() const override;
133 NoiseSuppression* noise_suppression() const override;
134 VoiceDetection* voice_detection() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
peah8271d042016-11-22 07:24:52 -0800136 // TODO(peah): Remove these two methods once the new API allows that.
137 void MutateConfig(rtc::FunctionView<void(AudioProcessing::Config*)> mutator);
138 AudioProcessing::Config GetConfig() const;
139
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000140 protected:
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000141 // Overridden in a mock.
peahdf3efa82015-11-28 12:35:15 -0800142 virtual int InitializeLocked()
143 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000144
niklase@google.com470e71d2011-07-07 08:21:25 +0000145 private:
peahc19f3122016-10-07 14:54:10 -0700146 // TODO(peah): These friend classes should be removed as soon as the new
147 // parameter setting scheme allows.
148 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior);
149 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior);
150 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior);
peahdf3efa82015-11-28 12:35:15 -0800151 struct ApmPublicSubmodules;
152 struct ApmPrivateSubmodules;
153
peah8271d042016-11-22 07:24:52 -0800154 // Submodule interface implementations.
155 std::unique_ptr<HighPassFilter> high_pass_filter_impl_;
156
peah2ace3f92016-09-10 04:42:27 -0700157 class ApmSubmoduleStates {
158 public:
159 ApmSubmoduleStates();
160 // Updates the submodule state and returns true if it has changed.
peah8271d042016-11-22 07:24:52 -0800161 bool Update(bool low_cut_filter_enabled,
peah2ace3f92016-09-10 04:42:27 -0700162 bool echo_canceller_enabled,
163 bool mobile_echo_controller_enabled,
ivoc9f4a4a02016-10-28 05:39:16 -0700164 bool residual_echo_detector_enabled,
peah2ace3f92016-09-10 04:42:27 -0700165 bool noise_suppressor_enabled,
166 bool intelligibility_enhancer_enabled,
167 bool beamformer_enabled,
168 bool adaptive_gain_controller_enabled,
169 bool level_controller_enabled,
170 bool voice_activity_detector_enabled,
171 bool level_estimator_enabled,
172 bool transient_suppressor_enabled);
173 bool CaptureMultiBandSubModulesActive() const;
174 bool CaptureMultiBandProcessingActive() const;
175 bool RenderMultiBandSubModulesActive() const;
176 bool RenderMultiBandProcessingActive() const;
177
178 private:
peah8271d042016-11-22 07:24:52 -0800179 bool low_cut_filter_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700180 bool echo_canceller_enabled_ = false;
181 bool mobile_echo_controller_enabled_ = false;
ivoc9f4a4a02016-10-28 05:39:16 -0700182 bool residual_echo_detector_enabled_ = false;
peah2ace3f92016-09-10 04:42:27 -0700183 bool noise_suppressor_enabled_ = false;
184 bool intelligibility_enhancer_enabled_ = false;
185 bool beamformer_enabled_ = false;
186 bool adaptive_gain_controller_enabled_ = false;
187 bool level_controller_enabled_ = false;
188 bool level_estimator_enabled_ = false;
189 bool voice_activity_detector_enabled_ = false;
190 bool transient_suppressor_enabled_ = false;
191 bool first_update_ = true;
192 };
193
peahdf3efa82015-11-28 12:35:15 -0800194#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
195 // State for the debug dump.
196 struct ApmDebugDumpThreadState {
kwiberg83ffe452016-08-29 14:46:07 -0700197 ApmDebugDumpThreadState();
198 ~ApmDebugDumpThreadState();
kwiberg88788ad2016-02-19 07:04:49 -0800199 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message.
peahdf3efa82015-11-28 12:35:15 -0800200 std::string event_str; // Memory for protobuf serialization.
201
202 // Serialized string of last saved APM configuration.
203 std::string last_serialized_config;
204 };
205
206 struct ApmDebugDumpState {
kwiberg83ffe452016-08-29 14:46:07 -0700207 ApmDebugDumpState();
208 ~ApmDebugDumpState();
ivocd66b44d2016-01-15 03:06:36 -0800209 // Number of bytes that can still be written to the log before the maximum
210 // size is reached. A value of <= 0 indicates that no limit is used.
211 int64_t num_bytes_left_for_log_ = -1;
kwiberg88788ad2016-02-19 07:04:49 -0800212 std::unique_ptr<FileWrapper> debug_file;
peahdf3efa82015-11-28 12:35:15 -0800213 ApmDebugDumpThreadState render;
214 ApmDebugDumpThreadState capture;
215 };
216#endif
217
218 // Method for modifying the formats struct that are called from both
219 // the render and capture threads. The check for whether modifications
220 // are needed is done while holding the render lock only, thereby avoiding
221 // that the capture thread blocks the render thread.
222 // The struct is modified in a single-threaded manner by holding both the
223 // render and capture locks.
peah2ace3f92016-09-10 04:42:27 -0700224 int MaybeInitialize(const ProcessingConfig& config, bool force_initialization)
peahdf3efa82015-11-28 12:35:15 -0800225 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
226
227 int MaybeInitializeRender(const ProcessingConfig& processing_config)
228 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
229
peah2ace3f92016-09-10 04:42:27 -0700230 int MaybeInitializeCapture(const ProcessingConfig& processing_config,
231 bool force_initialization)
peahdf3efa82015-11-28 12:35:15 -0800232 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
233
peah2ace3f92016-09-10 04:42:27 -0700234 // Method for updating the state keeping track of the active submodules.
235 // Returns a bool indicating whether the state has changed.
236 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800237
238 // Methods requiring APM running in a single-threaded manner.
239 // Are called with both the render and capture locks already
240 // acquired.
peahdf3efa82015-11-28 12:35:15 -0800241 void InitializeTransient()
242 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
243 void InitializeBeamformer()
244 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
245 void InitializeIntelligibility()
246 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700247 int InitializeLocked(const ProcessingConfig& config)
peahdf3efa82015-11-28 12:35:15 -0800248 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peahca4cac72016-06-29 15:26:12 -0700249 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
ivoc9f4a4a02016-10-28 05:39:16 -0700250 void InitializeResidualEchoDetector()
251 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peah8271d042016-11-22 07:24:52 -0800252 void InitializeLowCutFilter() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800253
peah764e3642016-10-22 05:04:30 -0700254 void EmptyQueuedRenderAudio();
255 void AllocateRenderQueue()
256 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peah701d6282016-10-25 05:42:20 -0700257 void QueueRenderAudio(AudioBuffer* audio)
peah764e3642016-10-22 05:04:30 -0700258 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
259
peahdf3efa82015-11-28 12:35:15 -0800260 // Capture-side exclusive methods possibly running APM in a multi-threaded
261 // manner that are called with the render lock already acquired.
peahde65ddc2016-09-16 15:02:15 -0700262 int ProcessCaptureStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800263 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
264
265 // Render-side exclusive methods possibly running APM in a multi-threaded
266 // manner that are called with the render lock already acquired.
ekmeyerson60d9b332015-08-14 10:35:55 -0700267 // TODO(ekm): Remove once all clients updated to new interface.
peahdf3efa82015-11-28 12:35:15 -0800268 int AnalyzeReverseStreamLocked(const float* const* src,
269 const StreamConfig& input_config,
270 const StreamConfig& output_config)
271 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahde65ddc2016-09-16 15:02:15 -0700272 int ProcessRenderStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000273
peahdf3efa82015-11-28 12:35:15 -0800274// Debug dump methods that are internal and called without locks.
275// TODO(peah): Make thread safe.
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000276#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
277 // TODO(andrew): make this more graceful. Ideally we would split this stuff
278 // out into a separate class with an "enabled" and "disabled" implementation.
peahdf3efa82015-11-28 12:35:15 -0800279 static int WriteMessageToDebugFile(FileWrapper* debug_file,
ivocd66b44d2016-01-15 03:06:36 -0800280 int64_t* filesize_limit_bytes,
peahdf3efa82015-11-28 12:35:15 -0800281 rtc::CriticalSection* crit_debug,
282 ApmDebugDumpThreadState* debug_state);
283 int WriteInitMessage() EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Minyue13b96ba2015-10-03 00:39:14 +0200284
285 // Writes Config message. If not |forced|, only writes the current config if
286 // it is different from the last saved one; if |forced|, writes the config
287 // regardless of the last saved.
peahdf3efa82015-11-28 12:35:15 -0800288 int WriteConfigMessage(bool forced) EXCLUSIVE_LOCKS_REQUIRED(crit_capture_)
289 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
Minyue13b96ba2015-10-03 00:39:14 +0200290
peahdf3efa82015-11-28 12:35:15 -0800291 // Critical section.
pbos5ad935c2016-01-25 03:52:44 -0800292 rtc::CriticalSection crit_debug_;
Minyue13b96ba2015-10-03 00:39:14 +0200293
peahdf3efa82015-11-28 12:35:15 -0800294 // Debug dump state.
295 ApmDebugDumpState debug_dump_;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000296#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
peahdf3efa82015-11-28 12:35:15 -0800298 // Critical sections.
pbos5ad935c2016-01-25 03:52:44 -0800299 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_);
300 rtc::CriticalSection crit_capture_;
peahdf3efa82015-11-28 12:35:15 -0800301
peahc19f3122016-10-07 14:54:10 -0700302 // Struct containing the Config specifying the behavior of APM.
303 AudioProcessing::Config config_;
304
peah2ace3f92016-09-10 04:42:27 -0700305 // Class containing information about what submodules are active.
306 ApmSubmoduleStates submodule_states_;
307
peahdf3efa82015-11-28 12:35:15 -0800308 // Structs containing the pointers to the submodules.
kwiberg88788ad2016-02-19 07:04:49 -0800309 std::unique_ptr<ApmPublicSubmodules> public_submodules_;
ivoc9f4a4a02016-10-28 05:39:16 -0700310 std::unique_ptr<ApmPrivateSubmodules> private_submodules_;
peahdf3efa82015-11-28 12:35:15 -0800311
peah192164e2015-11-17 02:16:45 -0800312 // State that is written to while holding both the render and capture locks
peahdf3efa82015-11-28 12:35:15 -0800313 // but can be read without any lock being held.
314 // As this is only accessed internally of APM, and all internal methods in APM
315 // either are holding the render or capture locks, this construct is safe as
316 // it is not possible to read the variables while writing them.
317 struct ApmFormatState {
318 ApmFormatState()
peah192164e2015-11-17 02:16:45 -0800319 : // Format of processing streams at input/output call sites.
peahdf3efa82015-11-28 12:35:15 -0800320 api_format({{{kSampleRate16kHz, 1, false},
321 {kSampleRate16kHz, 1, false},
322 {kSampleRate16kHz, 1, false},
323 {kSampleRate16kHz, 1, false}}}),
peahde65ddc2016-09-16 15:02:15 -0700324 render_processing_format(kSampleRate16kHz, 1) {}
peahdf3efa82015-11-28 12:35:15 -0800325 ProcessingConfig api_format;
peahde65ddc2016-09-16 15:02:15 -0700326 StreamConfig render_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800327 } formats_;
Michael Graczyk86c6d332015-07-23 11:41:39 -0700328
peahdf3efa82015-11-28 12:35:15 -0800329 // APM constants.
330 const struct ApmConstants {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700331 ApmConstants(int agc_startup_min_volume, bool use_experimental_agc)
peahdf3efa82015-11-28 12:35:15 -0800332 : // Format of processing streams at input/output call sites.
333 agc_startup_min_volume(agc_startup_min_volume),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700334 use_experimental_agc(use_experimental_agc) {}
peahdf3efa82015-11-28 12:35:15 -0800335 int agc_startup_min_volume;
peahbe615622016-02-13 16:40:47 -0800336 bool use_experimental_agc;
peahdf3efa82015-11-28 12:35:15 -0800337 } constants_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000338
peahdf3efa82015-11-28 12:35:15 -0800339 struct ApmCaptureState {
aluebs2a346882016-01-11 18:04:30 -0800340 ApmCaptureState(bool transient_suppressor_enabled,
aluebs2a346882016-01-11 18:04:30 -0800341 const std::vector<Point>& array_geometry,
kwiberg83ffe452016-08-29 14:46:07 -0700342 SphericalPointf target_direction);
343 ~ApmCaptureState();
peahdf3efa82015-11-28 12:35:15 -0800344 int aec_system_delay_jumps;
345 int delay_offset_ms;
346 bool was_stream_delay_set;
347 int last_stream_delay_ms;
348 int last_aec_system_delay_ms;
349 int stream_delay_jumps;
350 bool output_will_be_muted;
351 bool key_pressed;
352 bool transient_suppressor_enabled;
aluebs2a346882016-01-11 18:04:30 -0800353 std::vector<Point> array_geometry;
354 SphericalPointf target_direction;
kwiberg88788ad2016-02-19 07:04:49 -0800355 std::unique_ptr<AudioBuffer> capture_audio;
peahde65ddc2016-09-16 15:02:15 -0700356 // Only the rate and samples fields of capture_processing_format_ are used
357 // because the capture processing number of channels is mutable and is
358 // tracked by the capture_audio_.
359 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800360 int split_rate;
361 } capture_ GUARDED_BY(crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
peahdf3efa82015-11-28 12:35:15 -0800363 struct ApmCaptureNonLockedState {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700364 ApmCaptureNonLockedState(bool beamformer_enabled,
peah88ac8532016-09-12 16:47:25 -0700365 bool intelligibility_enabled)
peahde65ddc2016-09-16 15:02:15 -0700366 : capture_processing_format(kSampleRate16kHz),
peahdf3efa82015-11-28 12:35:15 -0800367 split_rate(kSampleRate16kHz),
aluebsb2328d12016-01-11 20:32:29 -0800368 stream_delay_ms(0),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700369 beamformer_enabled(beamformer_enabled),
peah88ac8532016-09-12 16:47:25 -0700370 intelligibility_enabled(intelligibility_enabled) {}
peahde65ddc2016-09-16 15:02:15 -0700371 // Only the rate and samples fields of capture_processing_format_ are used
372 // because the forward processing number of channels is mutable and is
373 // tracked by the capture_audio_.
374 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800375 int split_rate;
376 int stream_delay_ms;
aluebsb2328d12016-01-11 20:32:29 -0800377 bool beamformer_enabled;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700378 bool intelligibility_enabled;
peah88ac8532016-09-12 16:47:25 -0700379 bool level_controller_enabled = false;
peahdf3efa82015-11-28 12:35:15 -0800380 } capture_nonlocked_;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000381
peahdf3efa82015-11-28 12:35:15 -0800382 struct ApmRenderState {
kwiberg83ffe452016-08-29 14:46:07 -0700383 ApmRenderState();
384 ~ApmRenderState();
kwiberg88788ad2016-02-19 07:04:49 -0800385 std::unique_ptr<AudioConverter> render_converter;
386 std::unique_ptr<AudioBuffer> render_audio;
peahdf3efa82015-11-28 12:35:15 -0800387 } render_ GUARDED_BY(crit_render_);
peah764e3642016-10-22 05:04:30 -0700388
peah701d6282016-10-25 05:42:20 -0700389 size_t aec_render_queue_element_max_size_ GUARDED_BY(crit_render_)
peah764e3642016-10-22 05:04:30 -0700390 GUARDED_BY(crit_capture_) = 0;
peah701d6282016-10-25 05:42:20 -0700391 std::vector<float> aec_render_queue_buffer_ GUARDED_BY(crit_render_);
392 std::vector<float> aec_capture_queue_buffer_ GUARDED_BY(crit_capture_);
peaha0624602016-10-25 04:45:24 -0700393
peah701d6282016-10-25 05:42:20 -0700394 size_t aecm_render_queue_element_max_size_ GUARDED_BY(crit_render_)
peaha0624602016-10-25 04:45:24 -0700395 GUARDED_BY(crit_capture_) = 0;
peah701d6282016-10-25 05:42:20 -0700396 std::vector<int16_t> aecm_render_queue_buffer_ GUARDED_BY(crit_render_);
397 std::vector<int16_t> aecm_capture_queue_buffer_ GUARDED_BY(crit_capture_);
398
399 size_t agc_render_queue_element_max_size_ GUARDED_BY(crit_render_)
400 GUARDED_BY(crit_capture_) = 0;
401 std::vector<int16_t> agc_render_queue_buffer_ GUARDED_BY(crit_render_);
402 std::vector<int16_t> agc_capture_queue_buffer_ GUARDED_BY(crit_capture_);
peah764e3642016-10-22 05:04:30 -0700403
ivoc9f4a4a02016-10-28 05:39:16 -0700404 size_t red_render_queue_element_max_size_ GUARDED_BY(crit_render_)
405 GUARDED_BY(crit_capture_) = 0;
406 std::vector<float> red_render_queue_buffer_ GUARDED_BY(crit_render_);
407 std::vector<float> red_capture_queue_buffer_ GUARDED_BY(crit_capture_);
408
peah764e3642016-10-22 05:04:30 -0700409 // Lock protection not needed.
410 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
peah701d6282016-10-25 05:42:20 -0700411 aec_render_signal_queue_;
peaha0624602016-10-25 04:45:24 -0700412 std::unique_ptr<
413 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
peah701d6282016-10-25 05:42:20 -0700414 aecm_render_signal_queue_;
415 std::unique_ptr<
416 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
417 agc_render_signal_queue_;
ivoc9f4a4a02016-10-28 05:39:16 -0700418 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
419 red_render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000420};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000421
niklase@google.com470e71d2011-07-07 08:21:25 +0000422} // namespace webrtc
423
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000424#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_