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