niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 15 | #include <memory> |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 16 | #include <string> |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 17 | #include <vector> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 19 | #include "webrtc/base/criticalsection.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 20 | #include "webrtc/base/thread_annotations.h" |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 21 | #include "webrtc/modules/audio_processing/audio_buffer.h" |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 22 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 23 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 24 | |
| 25 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 26 | // Files generated at build-time by the protobuf compiler. |
| 27 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 28 | #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" |
| 29 | #else |
kjellander | 78ddd73 | 2016-02-09 08:13:06 -0800 | [diff] [blame] | 30 | #include "webrtc/modules/audio_processing/debug.pb.h" |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 31 | #endif |
| 32 | #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
| 34 | namespace webrtc { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 35 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 36 | class AgcManagerDirect; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 37 | class AudioConverter; |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 38 | |
Alejandro Luebs | f4022ff | 2016-07-01 17:19:09 -0700 | [diff] [blame] | 39 | class NonlinearBeamformer; |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 40 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | class AudioProcessingImpl : public AudioProcessing { |
| 42 | public: |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 43 | // Methods forcing APM to run in a single-threaded manner. |
| 44 | // Acquires both the render and capture locks. |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 45 | explicit AudioProcessingImpl(const webrtc::Config& config); |
Michael Graczyk | dfa3605 | 2015-03-25 16:37:27 -0700 | [diff] [blame] | 46 | // AudioProcessingImpl takes ownership of beamformer. |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 47 | AudioProcessingImpl(const webrtc::Config& config, |
| 48 | NonlinearBeamformer* beamformer); |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 49 | ~AudioProcessingImpl() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 50 | int Initialize() override; |
| 51 | int Initialize(int input_sample_rate_hz, |
| 52 | int output_sample_rate_hz, |
| 53 | int reverse_sample_rate_hz, |
| 54 | ChannelLayout input_layout, |
| 55 | ChannelLayout output_layout, |
| 56 | ChannelLayout reverse_layout) override; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 57 | int Initialize(const ProcessingConfig& processing_config) override; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 58 | void ApplyConfig(const AudioProcessing::Config& config) override; |
| 59 | void SetExtraOptions(const webrtc::Config& config) override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 60 | void UpdateHistogramsOnCallEnd() override; |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 61 | int StartDebugRecording(const char filename[kMaxFilenameSize], |
| 62 | int64_t max_log_size_bytes) override; |
| 63 | int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override; |
| 64 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 65 | int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; |
| 66 | int StopDebugRecording() override; |
| 67 | |
| 68 | // Capture-side exclusive methods possibly running APM in a |
| 69 | // multi-threaded manner. Acquire the capture lock. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 70 | int ProcessStream(AudioFrame* frame) override; |
| 71 | int ProcessStream(const float* const* src, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 72 | size_t samples_per_channel, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 73 | int input_sample_rate_hz, |
| 74 | ChannelLayout input_layout, |
| 75 | int output_sample_rate_hz, |
| 76 | ChannelLayout output_layout, |
| 77 | float* const* dest) override; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 78 | int ProcessStream(const float* const* src, |
| 79 | const StreamConfig& input_config, |
| 80 | const StreamConfig& output_config, |
| 81 | float* const* dest) override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 82 | void set_output_will_be_muted(bool muted) override; |
| 83 | int set_stream_delay_ms(int delay) override; |
| 84 | void set_delay_offset_ms(int offset) override; |
| 85 | int delay_offset_ms() const override; |
| 86 | void set_stream_key_pressed(bool key_pressed) override; |
| 87 | |
| 88 | // Render-side exclusive methods possibly running APM in a |
| 89 | // multi-threaded manner. Acquire the render lock. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 90 | int ProcessReverseStream(AudioFrame* frame) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 91 | int AnalyzeReverseStream(const float* const* data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 92 | size_t samples_per_channel, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 93 | int sample_rate_hz, |
| 94 | ChannelLayout layout) override; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 95 | int ProcessReverseStream(const float* const* src, |
| 96 | const StreamConfig& reverse_input_config, |
| 97 | const StreamConfig& reverse_output_config, |
| 98 | float* const* dest) override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 99 | |
| 100 | // Methods only accessed from APM submodules or |
| 101 | // from AudioProcessing tests in a single-threaded manner. |
| 102 | // Hence there is no need for locks in these. |
| 103 | int proc_sample_rate_hz() const override; |
| 104 | int proc_split_sample_rate_hz() const override; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 105 | size_t num_input_channels() const override; |
| 106 | size_t num_proc_channels() const override; |
| 107 | size_t num_output_channels() const override; |
| 108 | size_t num_reverse_channels() const override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 109 | int stream_delay_ms() const override; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 110 | bool was_stream_delay_set() const override |
| 111 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 112 | |
| 113 | // Methods returning pointers to APM submodules. |
| 114 | // No locks are aquired in those, as those locks |
| 115 | // would offer no protection (the submodules are |
| 116 | // created only once in a single-treaded manner |
| 117 | // during APM creation). |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 118 | EchoCancellation* echo_cancellation() const override; |
| 119 | EchoControlMobile* echo_control_mobile() const override; |
| 120 | GainControl* gain_control() const override; |
| 121 | HighPassFilter* high_pass_filter() const override; |
| 122 | LevelEstimator* level_estimator() const override; |
| 123 | NoiseSuppression* noise_suppression() const override; |
| 124 | VoiceDetection* voice_detection() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 126 | protected: |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 127 | // Overridden in a mock. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 128 | virtual int InitializeLocked() |
| 129 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 130 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | private: |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 132 | struct ApmPublicSubmodules; |
| 133 | struct ApmPrivateSubmodules; |
| 134 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 135 | class ApmSubmoduleStates { |
| 136 | public: |
| 137 | ApmSubmoduleStates(); |
| 138 | // Updates the submodule state and returns true if it has changed. |
| 139 | bool Update(bool high_pass_filter_enabled, |
| 140 | bool echo_canceller_enabled, |
| 141 | bool mobile_echo_controller_enabled, |
| 142 | bool noise_suppressor_enabled, |
| 143 | bool intelligibility_enhancer_enabled, |
| 144 | bool beamformer_enabled, |
| 145 | bool adaptive_gain_controller_enabled, |
| 146 | bool level_controller_enabled, |
| 147 | bool voice_activity_detector_enabled, |
| 148 | bool level_estimator_enabled, |
| 149 | bool transient_suppressor_enabled); |
| 150 | bool CaptureMultiBandSubModulesActive() const; |
| 151 | bool CaptureMultiBandProcessingActive() const; |
| 152 | bool RenderMultiBandSubModulesActive() const; |
| 153 | bool RenderMultiBandProcessingActive() const; |
| 154 | |
| 155 | private: |
| 156 | bool high_pass_filter_enabled_ = false; |
| 157 | bool echo_canceller_enabled_ = false; |
| 158 | bool mobile_echo_controller_enabled_ = false; |
| 159 | bool noise_suppressor_enabled_ = false; |
| 160 | bool intelligibility_enhancer_enabled_ = false; |
| 161 | bool beamformer_enabled_ = false; |
| 162 | bool adaptive_gain_controller_enabled_ = false; |
| 163 | bool level_controller_enabled_ = false; |
| 164 | bool level_estimator_enabled_ = false; |
| 165 | bool voice_activity_detector_enabled_ = false; |
| 166 | bool transient_suppressor_enabled_ = false; |
| 167 | bool first_update_ = true; |
| 168 | }; |
| 169 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 170 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 171 | // State for the debug dump. |
| 172 | struct ApmDebugDumpThreadState { |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 173 | ApmDebugDumpThreadState(); |
| 174 | ~ApmDebugDumpThreadState(); |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 175 | std::unique_ptr<audioproc::Event> event_msg; // Protobuf message. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 176 | std::string event_str; // Memory for protobuf serialization. |
| 177 | |
| 178 | // Serialized string of last saved APM configuration. |
| 179 | std::string last_serialized_config; |
| 180 | }; |
| 181 | |
| 182 | struct ApmDebugDumpState { |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 183 | ApmDebugDumpState(); |
| 184 | ~ApmDebugDumpState(); |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 185 | // Number of bytes that can still be written to the log before the maximum |
| 186 | // size is reached. A value of <= 0 indicates that no limit is used. |
| 187 | int64_t num_bytes_left_for_log_ = -1; |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 188 | std::unique_ptr<FileWrapper> debug_file; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 189 | ApmDebugDumpThreadState render; |
| 190 | ApmDebugDumpThreadState capture; |
| 191 | }; |
| 192 | #endif |
| 193 | |
| 194 | // Method for modifying the formats struct that are called from both |
| 195 | // the render and capture threads. The check for whether modifications |
| 196 | // are needed is done while holding the render lock only, thereby avoiding |
| 197 | // that the capture thread blocks the render thread. |
| 198 | // The struct is modified in a single-threaded manner by holding both the |
| 199 | // render and capture locks. |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 200 | int MaybeInitialize(const ProcessingConfig& config, bool force_initialization) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 201 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 202 | |
| 203 | int MaybeInitializeRender(const ProcessingConfig& processing_config) |
| 204 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 205 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 206 | int MaybeInitializeCapture(const ProcessingConfig& processing_config, |
| 207 | bool force_initialization) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 208 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
| 209 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 210 | // Method for updating the state keeping track of the active submodules. |
| 211 | // Returns a bool indicating whether the state has changed. |
| 212 | bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 213 | |
| 214 | // Methods requiring APM running in a single-threaded manner. |
| 215 | // Are called with both the render and capture locks already |
| 216 | // acquired. |
| 217 | void InitializeExperimentalAgc() |
| 218 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 219 | void InitializeTransient() |
| 220 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 221 | void InitializeBeamformer() |
| 222 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
| 223 | void InitializeIntelligibility() |
| 224 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
solenberg | 70f9903 | 2015-12-08 11:07:32 -0800 | [diff] [blame] | 225 | void InitializeHighPassFilter() |
| 226 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
solenberg | 5e465c3 | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 227 | void InitializeNoiseSuppression() |
| 228 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
solenberg | 949028f | 2015-12-15 11:39:38 -0800 | [diff] [blame] | 229 | void InitializeLevelEstimator() |
| 230 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 231 | void InitializeVoiceDetection() |
| 232 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
peah | b624d8c | 2016-03-05 03:01:14 -0800 | [diff] [blame] | 233 | void InitializeEchoCanceller() |
| 234 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 235 | void InitializeGainController() |
| 236 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 237 | void InitializeEchoControlMobile() |
| 238 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 239 | int InitializeLocked(const ProcessingConfig& config) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 240 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
peah | ca4cac7 | 2016-06-29 15:26:12 -0700 | [diff] [blame] | 241 | void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 242 | |
| 243 | // Capture-side exclusive methods possibly running APM in a multi-threaded |
| 244 | // manner that are called with the render lock already acquired. |
| 245 | int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 246 | void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
| 247 | |
| 248 | // Render-side exclusive methods possibly running APM in a multi-threaded |
| 249 | // manner that are called with the render lock already acquired. |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 250 | // TODO(ekm): Remove once all clients updated to new interface. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 251 | int AnalyzeReverseStreamLocked(const float* const* src, |
| 252 | const StreamConfig& input_config, |
| 253 | const StreamConfig& output_config) |
| 254 | EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 255 | int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 256 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 257 | // Debug dump methods that are internal and called without locks. |
| 258 | // TODO(peah): Make thread safe. |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 259 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 260 | // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 261 | // out into a separate class with an "enabled" and "disabled" implementation. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 262 | static int WriteMessageToDebugFile(FileWrapper* debug_file, |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 263 | int64_t* filesize_limit_bytes, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 264 | rtc::CriticalSection* crit_debug, |
| 265 | ApmDebugDumpThreadState* debug_state); |
| 266 | int WriteInitMessage() EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 267 | |
| 268 | // Writes Config message. If not |forced|, only writes the current config if |
| 269 | // it is different from the last saved one; if |forced|, writes the config |
| 270 | // regardless of the last saved. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 271 | int WriteConfigMessage(bool forced) EXCLUSIVE_LOCKS_REQUIRED(crit_capture_) |
| 272 | EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 273 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 274 | // Critical section. |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 275 | rtc::CriticalSection crit_debug_; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 276 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 277 | // Debug dump state. |
| 278 | ApmDebugDumpState debug_dump_; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 279 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 281 | // Critical sections. |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 282 | rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_); |
| 283 | rtc::CriticalSection crit_capture_; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 284 | |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 285 | // Class containing information about what submodules are active. |
| 286 | ApmSubmoduleStates submodule_states_; |
| 287 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 288 | // Structs containing the pointers to the submodules. |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 289 | std::unique_ptr<ApmPublicSubmodules> public_submodules_; |
| 290 | std::unique_ptr<ApmPrivateSubmodules> private_submodules_ |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 291 | GUARDED_BY(crit_capture_); |
| 292 | |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 293 | // State that is written to while holding both the render and capture locks |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 294 | // but can be read without any lock being held. |
| 295 | // As this is only accessed internally of APM, and all internal methods in APM |
| 296 | // either are holding the render or capture locks, this construct is safe as |
| 297 | // it is not possible to read the variables while writing them. |
| 298 | struct ApmFormatState { |
| 299 | ApmFormatState() |
peah | 192164e | 2015-11-17 02:16:45 -0800 | [diff] [blame] | 300 | : // Format of processing streams at input/output call sites. |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 301 | api_format({{{kSampleRate16kHz, 1, false}, |
| 302 | {kSampleRate16kHz, 1, false}, |
| 303 | {kSampleRate16kHz, 1, false}, |
| 304 | {kSampleRate16kHz, 1, false}}}), |
| 305 | rev_proc_format(kSampleRate16kHz, 1) {} |
| 306 | ProcessingConfig api_format; |
| 307 | StreamConfig rev_proc_format; |
| 308 | } formats_; |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 309 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 310 | // APM constants. |
| 311 | const struct ApmConstants { |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 312 | ApmConstants(int agc_startup_min_volume, bool use_experimental_agc) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 313 | : // Format of processing streams at input/output call sites. |
| 314 | agc_startup_min_volume(agc_startup_min_volume), |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 315 | use_experimental_agc(use_experimental_agc) {} |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 316 | int agc_startup_min_volume; |
peah | be61562 | 2016-02-13 16:40:47 -0800 | [diff] [blame] | 317 | bool use_experimental_agc; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 318 | } constants_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 319 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 320 | struct ApmCaptureState { |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 321 | ApmCaptureState(bool transient_suppressor_enabled, |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 322 | const std::vector<Point>& array_geometry, |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 323 | SphericalPointf target_direction); |
| 324 | ~ApmCaptureState(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 325 | int aec_system_delay_jumps; |
| 326 | int delay_offset_ms; |
| 327 | bool was_stream_delay_set; |
| 328 | int last_stream_delay_ms; |
| 329 | int last_aec_system_delay_ms; |
| 330 | int stream_delay_jumps; |
| 331 | bool output_will_be_muted; |
| 332 | bool key_pressed; |
| 333 | bool transient_suppressor_enabled; |
aluebs | 2a34688 | 2016-01-11 18:04:30 -0800 | [diff] [blame] | 334 | std::vector<Point> array_geometry; |
| 335 | SphericalPointf target_direction; |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 336 | std::unique_ptr<AudioBuffer> capture_audio; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 337 | // Only the rate and samples fields of fwd_proc_format_ are used because the |
| 338 | // forward processing number of channels is mutable and is tracked by the |
| 339 | // capture_audio_. |
| 340 | StreamConfig fwd_proc_format; |
| 341 | int split_rate; |
| 342 | } capture_ GUARDED_BY(crit_capture_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 344 | struct ApmCaptureNonLockedState { |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 345 | ApmCaptureNonLockedState(bool beamformer_enabled, |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 346 | bool intelligibility_enabled) |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 347 | : fwd_proc_format(kSampleRate16kHz), |
| 348 | split_rate(kSampleRate16kHz), |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 349 | stream_delay_ms(0), |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 350 | beamformer_enabled(beamformer_enabled), |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 351 | intelligibility_enabled(intelligibility_enabled) {} |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 352 | // Only the rate and samples fields of fwd_proc_format_ are used because the |
| 353 | // forward processing number of channels is mutable and is tracked by the |
| 354 | // capture_audio_. |
| 355 | StreamConfig fwd_proc_format; |
| 356 | int split_rate; |
| 357 | int stream_delay_ms; |
aluebs | b2328d1 | 2016-01-11 20:32:29 -0800 | [diff] [blame] | 358 | bool beamformer_enabled; |
Alejandro Luebs | c9b0c26 | 2016-05-16 15:32:38 -0700 | [diff] [blame] | 359 | bool intelligibility_enabled; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame^] | 360 | bool level_controller_enabled = false; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 361 | } capture_nonlocked_; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 362 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 363 | struct ApmRenderState { |
kwiberg | 83ffe45 | 2016-08-29 14:46:07 -0700 | [diff] [blame] | 364 | ApmRenderState(); |
| 365 | ~ApmRenderState(); |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 366 | std::unique_ptr<AudioConverter> render_converter; |
| 367 | std::unique_ptr<AudioBuffer> render_audio; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 368 | } render_ GUARDED_BY(crit_render_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 370 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | } // namespace webrtc |
| 372 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 373 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |