blob: 817b6b2fe8ad8ce7cbbe66383702c1095bd90420 [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"
peahc19f3122016-10-07 14:54:10 -070020#include "webrtc/base/gtest_prod_util.h"
kwiberg77eab702016-09-28 17:42:01 -070021#include "webrtc/base/ignore_wundef.h"
peah764e3642016-10-22 05:04:30 -070022#include "webrtc/base/swap_queue.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000023#include "webrtc/base/thread_annotations.h"
peahdf3efa82015-11-28 12:35:15 -080024#include "webrtc/modules/audio_processing/audio_buffer.h"
Michael Graczykdfa36052015-03-25 16:37:27 -070025#include "webrtc/modules/audio_processing/include/audio_processing.h"
peah764e3642016-10-22 05:04:30 -070026#include "webrtc/modules/audio_processing/render_queue_item_verifier.h"
peahdf3efa82015-11-28 12:35:15 -080027#include "webrtc/system_wrappers/include/file_wrapper.h"
28
29#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
30// Files generated at build-time by the protobuf compiler.
kwiberg77eab702016-09-28 17:42:01 -070031RTC_PUSH_IGNORING_WUNDEF()
peahdf3efa82015-11-28 12:35:15 -080032#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
33#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
34#else
kjellander78ddd732016-02-09 08:13:06 -080035#include "webrtc/modules/audio_processing/debug.pb.h"
peahdf3efa82015-11-28 12:35:15 -080036#endif
kwiberg77eab702016-09-28 17:42:01 -070037RTC_POP_IGNORING_WUNDEF()
peahdf3efa82015-11-28 12:35:15 -080038#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +000039
40namespace webrtc {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000041
pbos@webrtc.org788acd12014-12-15 09:41:24 +000042class AgcManagerDirect;
ekmeyerson60d9b332015-08-14 10:35:55 -070043class AudioConverter;
Michael Graczykdfa36052015-03-25 16:37:27 -070044
Alejandro Luebsf4022ff2016-07-01 17:19:09 -070045class NonlinearBeamformer;
Michael Graczykdfa36052015-03-25 16:37:27 -070046
niklase@google.com470e71d2011-07-07 08:21:25 +000047class AudioProcessingImpl : public AudioProcessing {
48 public:
peahdf3efa82015-11-28 12:35:15 -080049 // Methods forcing APM to run in a single-threaded manner.
50 // Acquires both the render and capture locks.
peah88ac8532016-09-12 16:47:25 -070051 explicit AudioProcessingImpl(const webrtc::Config& config);
Michael Graczykdfa36052015-03-25 16:37:27 -070052 // AudioProcessingImpl takes ownership of beamformer.
peah88ac8532016-09-12 16:47:25 -070053 AudioProcessingImpl(const webrtc::Config& config,
54 NonlinearBeamformer* beamformer);
kwiberg83ffe452016-08-29 14:46:07 -070055 ~AudioProcessingImpl() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 int Initialize() override;
peahde65ddc2016-09-16 15:02:15 -070057 int Initialize(int capture_input_sample_rate_hz,
58 int capture_output_sample_rate_hz,
59 int render_sample_rate_hz,
60 ChannelLayout capture_input_layout,
61 ChannelLayout capture_output_layout,
62 ChannelLayout render_input_layout) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070063 int Initialize(const ProcessingConfig& processing_config) override;
peah88ac8532016-09-12 16:47:25 -070064 void ApplyConfig(const AudioProcessing::Config& config) override;
65 void SetExtraOptions(const webrtc::Config& config) override;
peahdf3efa82015-11-28 12:35:15 -080066 void UpdateHistogramsOnCallEnd() override;
ivocd66b44d2016-01-15 03:06:36 -080067 int StartDebugRecording(const char filename[kMaxFilenameSize],
68 int64_t max_log_size_bytes) override;
69 int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override;
peah73a28ee2016-10-12 03:01:49 -070070 int StartDebugRecording(FILE* handle) override;
peahdf3efa82015-11-28 12:35:15 -080071 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override;
72 int StopDebugRecording() override;
73
74 // Capture-side exclusive methods possibly running APM in a
75 // multi-threaded manner. Acquire the capture lock.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 int ProcessStream(AudioFrame* frame) override;
77 int ProcessStream(const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070078 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000079 int input_sample_rate_hz,
80 ChannelLayout input_layout,
81 int output_sample_rate_hz,
82 ChannelLayout output_layout,
83 float* const* dest) override;
Michael Graczyk86c6d332015-07-23 11:41:39 -070084 int ProcessStream(const float* const* src,
85 const StreamConfig& input_config,
86 const StreamConfig& output_config,
87 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -080088 void set_output_will_be_muted(bool muted) override;
89 int set_stream_delay_ms(int delay) override;
90 void set_delay_offset_ms(int offset) override;
91 int delay_offset_ms() const override;
92 void set_stream_key_pressed(bool key_pressed) override;
93
94 // Render-side exclusive methods possibly running APM in a
95 // multi-threaded manner. Acquire the render lock.
ekmeyerson60d9b332015-08-14 10:35:55 -070096 int ProcessReverseStream(AudioFrame* frame) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000097 int AnalyzeReverseStream(const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -070098 size_t samples_per_channel,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000099 int sample_rate_hz,
100 ChannelLayout layout) override;
ekmeyerson60d9b332015-08-14 10:35:55 -0700101 int ProcessReverseStream(const float* const* src,
peahde65ddc2016-09-16 15:02:15 -0700102 const StreamConfig& input_config,
103 const StreamConfig& output_config,
ekmeyerson60d9b332015-08-14 10:35:55 -0700104 float* const* dest) override;
peahdf3efa82015-11-28 12:35:15 -0800105
106 // Methods only accessed from APM submodules or
107 // from AudioProcessing tests in a single-threaded manner.
108 // Hence there is no need for locks in these.
109 int proc_sample_rate_hz() const override;
110 int proc_split_sample_rate_hz() const override;
Peter Kasting69558702016-01-12 16:26:35 -0800111 size_t num_input_channels() const override;
112 size_t num_proc_channels() const override;
113 size_t num_output_channels() const override;
114 size_t num_reverse_channels() const override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000115 int stream_delay_ms() const override;
peahdf3efa82015-11-28 12:35:15 -0800116 bool was_stream_delay_set() const override
117 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
118
119 // Methods returning pointers to APM submodules.
120 // No locks are aquired in those, as those locks
121 // would offer no protection (the submodules are
122 // created only once in a single-treaded manner
123 // during APM creation).
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000124 EchoCancellation* echo_cancellation() const override;
125 EchoControlMobile* echo_control_mobile() const override;
126 GainControl* gain_control() const override;
127 HighPassFilter* high_pass_filter() const override;
128 LevelEstimator* level_estimator() const override;
129 NoiseSuppression* noise_suppression() const override;
130 VoiceDetection* voice_detection() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000132 protected:
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000133 // Overridden in a mock.
peahdf3efa82015-11-28 12:35:15 -0800134 virtual int InitializeLocked()
135 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000136
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 private:
peahc19f3122016-10-07 14:54:10 -0700138 // TODO(peah): These friend classes should be removed as soon as the new
139 // parameter setting scheme allows.
140 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior);
141 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior);
142 FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior);
peahdf3efa82015-11-28 12:35:15 -0800143 struct ApmPublicSubmodules;
144 struct ApmPrivateSubmodules;
145
peah2ace3f92016-09-10 04:42:27 -0700146 class ApmSubmoduleStates {
147 public:
148 ApmSubmoduleStates();
149 // Updates the submodule state and returns true if it has changed.
150 bool Update(bool high_pass_filter_enabled,
151 bool echo_canceller_enabled,
152 bool mobile_echo_controller_enabled,
153 bool noise_suppressor_enabled,
154 bool intelligibility_enhancer_enabled,
155 bool beamformer_enabled,
156 bool adaptive_gain_controller_enabled,
157 bool level_controller_enabled,
158 bool voice_activity_detector_enabled,
159 bool level_estimator_enabled,
160 bool transient_suppressor_enabled);
161 bool CaptureMultiBandSubModulesActive() const;
162 bool CaptureMultiBandProcessingActive() const;
163 bool RenderMultiBandSubModulesActive() const;
164 bool RenderMultiBandProcessingActive() const;
165
166 private:
167 bool high_pass_filter_enabled_ = false;
168 bool echo_canceller_enabled_ = false;
169 bool mobile_echo_controller_enabled_ = false;
170 bool noise_suppressor_enabled_ = false;
171 bool intelligibility_enhancer_enabled_ = false;
172 bool beamformer_enabled_ = false;
173 bool adaptive_gain_controller_enabled_ = false;
174 bool level_controller_enabled_ = false;
175 bool level_estimator_enabled_ = false;
176 bool voice_activity_detector_enabled_ = false;
177 bool transient_suppressor_enabled_ = false;
178 bool first_update_ = true;
179 };
180
peahdf3efa82015-11-28 12:35:15 -0800181#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
182 // State for the debug dump.
183 struct ApmDebugDumpThreadState {
kwiberg83ffe452016-08-29 14:46:07 -0700184 ApmDebugDumpThreadState();
185 ~ApmDebugDumpThreadState();
kwiberg88788ad2016-02-19 07:04:49 -0800186 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message.
peahdf3efa82015-11-28 12:35:15 -0800187 std::string event_str; // Memory for protobuf serialization.
188
189 // Serialized string of last saved APM configuration.
190 std::string last_serialized_config;
191 };
192
193 struct ApmDebugDumpState {
kwiberg83ffe452016-08-29 14:46:07 -0700194 ApmDebugDumpState();
195 ~ApmDebugDumpState();
ivocd66b44d2016-01-15 03:06:36 -0800196 // Number of bytes that can still be written to the log before the maximum
197 // size is reached. A value of <= 0 indicates that no limit is used.
198 int64_t num_bytes_left_for_log_ = -1;
kwiberg88788ad2016-02-19 07:04:49 -0800199 std::unique_ptr<FileWrapper> debug_file;
peahdf3efa82015-11-28 12:35:15 -0800200 ApmDebugDumpThreadState render;
201 ApmDebugDumpThreadState capture;
202 };
203#endif
204
205 // Method for modifying the formats struct that are called from both
206 // the render and capture threads. The check for whether modifications
207 // are needed is done while holding the render lock only, thereby avoiding
208 // that the capture thread blocks the render thread.
209 // The struct is modified in a single-threaded manner by holding both the
210 // render and capture locks.
peah2ace3f92016-09-10 04:42:27 -0700211 int MaybeInitialize(const ProcessingConfig& config, bool force_initialization)
peahdf3efa82015-11-28 12:35:15 -0800212 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
213
214 int MaybeInitializeRender(const ProcessingConfig& processing_config)
215 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
216
peah2ace3f92016-09-10 04:42:27 -0700217 int MaybeInitializeCapture(const ProcessingConfig& processing_config,
218 bool force_initialization)
peahdf3efa82015-11-28 12:35:15 -0800219 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
220
peah2ace3f92016-09-10 04:42:27 -0700221 // Method for updating the state keeping track of the active submodules.
222 // Returns a bool indicating whether the state has changed.
223 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800224
225 // Methods requiring APM running in a single-threaded manner.
226 // Are called with both the render and capture locks already
227 // acquired.
peahdf3efa82015-11-28 12:35:15 -0800228 void InitializeTransient()
229 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
230 void InitializeBeamformer()
231 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
232 void InitializeIntelligibility()
233 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700234 int InitializeLocked(const ProcessingConfig& config)
peahdf3efa82015-11-28 12:35:15 -0800235 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
peahca4cac72016-06-29 15:26:12 -0700236 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800237
peah764e3642016-10-22 05:04:30 -0700238 void EmptyQueuedRenderAudio();
239 void AllocateRenderQueue()
240 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
241 void QueueRenderAudio(const AudioBuffer* audio)
242 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
243
peahdf3efa82015-11-28 12:35:15 -0800244 // Capture-side exclusive methods possibly running APM in a multi-threaded
245 // manner that are called with the render lock already acquired.
peahde65ddc2016-09-16 15:02:15 -0700246 int ProcessCaptureStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
peahdf3efa82015-11-28 12:35:15 -0800247 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
248
249 // Render-side exclusive methods possibly running APM in a multi-threaded
250 // manner that are called with the render lock already acquired.
ekmeyerson60d9b332015-08-14 10:35:55 -0700251 // TODO(ekm): Remove once all clients updated to new interface.
peahdf3efa82015-11-28 12:35:15 -0800252 int AnalyzeReverseStreamLocked(const float* const* src,
253 const StreamConfig& input_config,
254 const StreamConfig& output_config)
255 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
peahde65ddc2016-09-16 15:02:15 -0700256 int ProcessRenderStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000257
peahdf3efa82015-11-28 12:35:15 -0800258// Debug dump methods that are internal and called without locks.
259// TODO(peah): Make thread safe.
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000260#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
261 // TODO(andrew): make this more graceful. Ideally we would split this stuff
262 // out into a separate class with an "enabled" and "disabled" implementation.
peahdf3efa82015-11-28 12:35:15 -0800263 static int WriteMessageToDebugFile(FileWrapper* debug_file,
ivocd66b44d2016-01-15 03:06:36 -0800264 int64_t* filesize_limit_bytes,
peahdf3efa82015-11-28 12:35:15 -0800265 rtc::CriticalSection* crit_debug,
266 ApmDebugDumpThreadState* debug_state);
267 int WriteInitMessage() EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
Minyue13b96ba2015-10-03 00:39:14 +0200268
269 // Writes Config message. If not |forced|, only writes the current config if
270 // it is different from the last saved one; if |forced|, writes the config
271 // regardless of the last saved.
peahdf3efa82015-11-28 12:35:15 -0800272 int WriteConfigMessage(bool forced) EXCLUSIVE_LOCKS_REQUIRED(crit_capture_)
273 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
Minyue13b96ba2015-10-03 00:39:14 +0200274
peahdf3efa82015-11-28 12:35:15 -0800275 // Critical section.
pbos5ad935c2016-01-25 03:52:44 -0800276 rtc::CriticalSection crit_debug_;
Minyue13b96ba2015-10-03 00:39:14 +0200277
peahdf3efa82015-11-28 12:35:15 -0800278 // Debug dump state.
279 ApmDebugDumpState debug_dump_;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000280#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000281
peahdf3efa82015-11-28 12:35:15 -0800282 // Critical sections.
pbos5ad935c2016-01-25 03:52:44 -0800283 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_);
284 rtc::CriticalSection crit_capture_;
peahdf3efa82015-11-28 12:35:15 -0800285
peahc19f3122016-10-07 14:54:10 -0700286 // Struct containing the Config specifying the behavior of APM.
287 AudioProcessing::Config config_;
288
peah2ace3f92016-09-10 04:42:27 -0700289 // Class containing information about what submodules are active.
290 ApmSubmoduleStates submodule_states_;
291
peahdf3efa82015-11-28 12:35:15 -0800292 // Structs containing the pointers to the submodules.
kwiberg88788ad2016-02-19 07:04:49 -0800293 std::unique_ptr<ApmPublicSubmodules> public_submodules_;
294 std::unique_ptr<ApmPrivateSubmodules> private_submodules_
peahdf3efa82015-11-28 12:35:15 -0800295 GUARDED_BY(crit_capture_);
296
peah192164e2015-11-17 02:16:45 -0800297 // State that is written to while holding both the render and capture locks
peahdf3efa82015-11-28 12:35:15 -0800298 // but can be read without any lock being held.
299 // As this is only accessed internally of APM, and all internal methods in APM
300 // either are holding the render or capture locks, this construct is safe as
301 // it is not possible to read the variables while writing them.
302 struct ApmFormatState {
303 ApmFormatState()
peah192164e2015-11-17 02:16:45 -0800304 : // Format of processing streams at input/output call sites.
peahdf3efa82015-11-28 12:35:15 -0800305 api_format({{{kSampleRate16kHz, 1, false},
306 {kSampleRate16kHz, 1, false},
307 {kSampleRate16kHz, 1, false},
308 {kSampleRate16kHz, 1, false}}}),
peahde65ddc2016-09-16 15:02:15 -0700309 render_processing_format(kSampleRate16kHz, 1) {}
peahdf3efa82015-11-28 12:35:15 -0800310 ProcessingConfig api_format;
peahde65ddc2016-09-16 15:02:15 -0700311 StreamConfig render_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800312 } formats_;
Michael Graczyk86c6d332015-07-23 11:41:39 -0700313
peahdf3efa82015-11-28 12:35:15 -0800314 // APM constants.
315 const struct ApmConstants {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700316 ApmConstants(int agc_startup_min_volume, 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),
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;
peahbe615622016-02-13 16:40:47 -0800321 bool use_experimental_agc;
peahdf3efa82015-11-28 12:35:15 -0800322 } constants_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000323
peahdf3efa82015-11-28 12:35:15 -0800324 struct ApmCaptureState {
aluebs2a346882016-01-11 18:04:30 -0800325 ApmCaptureState(bool transient_suppressor_enabled,
aluebs2a346882016-01-11 18:04:30 -0800326 const std::vector<Point>& array_geometry,
kwiberg83ffe452016-08-29 14:46:07 -0700327 SphericalPointf target_direction);
328 ~ApmCaptureState();
peahdf3efa82015-11-28 12:35:15 -0800329 int aec_system_delay_jumps;
330 int delay_offset_ms;
331 bool was_stream_delay_set;
332 int last_stream_delay_ms;
333 int last_aec_system_delay_ms;
334 int stream_delay_jumps;
335 bool output_will_be_muted;
336 bool key_pressed;
337 bool transient_suppressor_enabled;
aluebs2a346882016-01-11 18:04:30 -0800338 std::vector<Point> array_geometry;
339 SphericalPointf target_direction;
kwiberg88788ad2016-02-19 07:04:49 -0800340 std::unique_ptr<AudioBuffer> capture_audio;
peahde65ddc2016-09-16 15:02:15 -0700341 // Only the rate and samples fields of capture_processing_format_ are used
342 // because the capture processing number of channels is mutable and is
343 // tracked by the capture_audio_.
344 StreamConfig capture_processing_format;
peahdf3efa82015-11-28 12:35:15 -0800345 int split_rate;
346 } capture_ GUARDED_BY(crit_capture_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000347
peahdf3efa82015-11-28 12:35:15 -0800348 struct ApmCaptureNonLockedState {
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700349 ApmCaptureNonLockedState(bool beamformer_enabled,
peah88ac8532016-09-12 16:47:25 -0700350 bool intelligibility_enabled)
peahde65ddc2016-09-16 15:02:15 -0700351 : capture_processing_format(kSampleRate16kHz),
peahdf3efa82015-11-28 12:35:15 -0800352 split_rate(kSampleRate16kHz),
aluebsb2328d12016-01-11 20:32:29 -0800353 stream_delay_ms(0),
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700354 beamformer_enabled(beamformer_enabled),
peah88ac8532016-09-12 16:47:25 -0700355 intelligibility_enabled(intelligibility_enabled) {}
peahde65ddc2016-09-16 15:02:15 -0700356 // Only the rate and samples fields of capture_processing_format_ are used
357 // because the forward 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 int stream_delay_ms;
aluebsb2328d12016-01-11 20:32:29 -0800362 bool beamformer_enabled;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700363 bool intelligibility_enabled;
peah88ac8532016-09-12 16:47:25 -0700364 bool level_controller_enabled = false;
peahdf3efa82015-11-28 12:35:15 -0800365 } capture_nonlocked_;
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000366
peahdf3efa82015-11-28 12:35:15 -0800367 struct ApmRenderState {
kwiberg83ffe452016-08-29 14:46:07 -0700368 ApmRenderState();
369 ~ApmRenderState();
kwiberg88788ad2016-02-19 07:04:49 -0800370 std::unique_ptr<AudioConverter> render_converter;
371 std::unique_ptr<AudioBuffer> render_audio;
peahdf3efa82015-11-28 12:35:15 -0800372 } render_ GUARDED_BY(crit_render_);
peah764e3642016-10-22 05:04:30 -0700373
peaha0624602016-10-25 04:45:24 -0700374 size_t float_render_queue_element_max_size_ GUARDED_BY(crit_render_)
peah764e3642016-10-22 05:04:30 -0700375 GUARDED_BY(crit_capture_) = 0;
peaha0624602016-10-25 04:45:24 -0700376 std::vector<float> float_render_queue_buffer_ GUARDED_BY(crit_render_);
377 std::vector<float> float_capture_queue_buffer_ GUARDED_BY(crit_capture_);
378
379 size_t int16_render_queue_element_max_size_ GUARDED_BY(crit_render_)
380 GUARDED_BY(crit_capture_) = 0;
381 std::vector<int16_t> int16_render_queue_buffer_ GUARDED_BY(crit_render_);
382 std::vector<int16_t> int16_capture_queue_buffer_ GUARDED_BY(crit_capture_);
peah764e3642016-10-22 05:04:30 -0700383
384 // Lock protection not needed.
385 std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
peaha0624602016-10-25 04:45:24 -0700386 float_render_signal_queue_;
387 std::unique_ptr<
388 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
389 int16_render_signal_queue_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000390};
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000391
niklase@google.com470e71d2011-07-07 08:21:25 +0000392} // namespace webrtc
393
pbos@webrtc.org788acd12014-12-15 09:41:24 +0000394#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_