OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 123 |
124 protected: | 124 protected: |
125 // Overridden in a mock. | 125 // Overridden in a mock. |
126 virtual int InitializeLocked() | 126 virtual int InitializeLocked() |
127 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 127 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
128 | 128 |
129 private: | 129 private: |
130 struct ApmPublicSubmodules; | 130 struct ApmPublicSubmodules; |
131 struct ApmPrivateSubmodules; | 131 struct ApmPrivateSubmodules; |
132 | 132 |
133 class ApmSubmoduleStates { | |
134 public: | |
135 ApmSubmoduleStates(); | |
136 // Updates the submodule state and returns true if it has changed. | |
137 bool Update(bool high_pass_filter_enabled, | |
138 bool echo_canceller_enabled, | |
139 bool mobile_echo_controller_enabled, | |
140 bool noise_suppressor_enabled, | |
141 bool intelligibility_enhancer_enabled, | |
142 bool beamformer_enabled, | |
143 bool adaptive_gain_controller_enabled, | |
144 bool level_controller_enabled, | |
145 bool voice_activity_detector_enabled, | |
146 bool level_estimator_enabled, | |
147 bool transient_suppressor_enabled); | |
148 bool CaptureMultiBandModulesActive() const; | |
149 bool CaptureMultiBandEffectsActive() const; | |
150 bool RenderMultiBandModulesActive() const; | |
151 bool RenderMultiBandEffectsActive() const; | |
152 | |
153 private: | |
154 bool high_pass_filter_enabled_ = false; | |
155 bool echo_canceller_enabled_ = false; | |
156 bool mobile_echo_controller_enabled_ = false; | |
157 bool noise_suppressor_enabled_ = false; | |
158 bool intelligibility_enhancer_enabled_ = false; | |
159 bool beamformer_enabled_ = false; | |
160 bool adaptive_gain_controller_enabled_ = false; | |
161 bool level_controller_enabled_ = false; | |
162 bool level_estimator_enabled_ = false; | |
163 bool voice_activity_detector_enabled_ = false; | |
164 bool transient_suppressor_enabled_ = false; | |
165 bool first_update_ = true; | |
166 }; | |
167 | |
133 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 168 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
134 // State for the debug dump. | 169 // State for the debug dump. |
135 struct ApmDebugDumpThreadState { | 170 struct ApmDebugDumpThreadState { |
136 ApmDebugDumpThreadState(); | 171 ApmDebugDumpThreadState(); |
137 ~ApmDebugDumpThreadState(); | 172 ~ApmDebugDumpThreadState(); |
138 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message. | 173 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message. |
139 std::string event_str; // Memory for protobuf serialization. | 174 std::string event_str; // Memory for protobuf serialization. |
140 | 175 |
141 // Serialized string of last saved APM configuration. | 176 // Serialized string of last saved APM configuration. |
142 std::string last_serialized_config; | 177 std::string last_serialized_config; |
(...skipping 10 matching lines...) Expand all Loading... | |
153 ApmDebugDumpThreadState capture; | 188 ApmDebugDumpThreadState capture; |
154 }; | 189 }; |
155 #endif | 190 #endif |
156 | 191 |
157 // Method for modifying the formats struct that are called from both | 192 // Method for modifying the formats struct that are called from both |
158 // the render and capture threads. The check for whether modifications | 193 // the render and capture threads. The check for whether modifications |
159 // are needed is done while holding the render lock only, thereby avoiding | 194 // are needed is done while holding the render lock only, thereby avoiding |
160 // that the capture thread blocks the render thread. | 195 // that the capture thread blocks the render thread. |
161 // The struct is modified in a single-threaded manner by holding both the | 196 // The struct is modified in a single-threaded manner by holding both the |
162 // render and capture locks. | 197 // render and capture locks. |
163 int MaybeInitialize(const ProcessingConfig& config) | 198 int MaybeInitialize(const ProcessingConfig& config, bool force_initialization) |
164 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | 199 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
165 | 200 |
166 int MaybeInitializeRender(const ProcessingConfig& processing_config) | 201 int MaybeInitializeRender(const ProcessingConfig& processing_config) |
167 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | 202 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
168 | 203 |
169 int MaybeInitializeCapture(const ProcessingConfig& processing_config) | 204 int MaybeInitializeCapture(const ProcessingConfig& processing_config, |
205 bool force_initialization) | |
170 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | 206 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
171 | 207 |
172 // Method for checking for the need of conversion. Accesses the formats | 208 // Method for updating the state keeping track of the active submodules. |
173 // structs in a read manner but the requirement for the render lock to be held | 209 // Returns a bool indicating whether the state had changed. |
the sun
2016/09/08 08:10:15
nit: had -> has
peah-webrtc
2016/09/08 08:44:04
Done.
| |
174 // was added as it currently anyway is always called in that manner. | 210 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
175 bool rev_conversion_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | |
176 bool render_check_rev_conversion_needed() const | |
177 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | |
178 | 211 |
179 // Methods requiring APM running in a single-threaded manner. | 212 // Methods requiring APM running in a single-threaded manner. |
180 // Are called with both the render and capture locks already | 213 // Are called with both the render and capture locks already |
181 // acquired. | 214 // acquired. |
182 void InitializeExperimentalAgc() | 215 void InitializeExperimentalAgc() |
183 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 216 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
184 void InitializeTransient() | 217 void InitializeTransient() |
185 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 218 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
186 void InitializeBeamformer() | 219 void InitializeBeamformer() |
187 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 220 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
(...skipping 13 matching lines...) Expand all Loading... | |
201 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 234 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
202 void InitializeEchoControlMobile() | 235 void InitializeEchoControlMobile() |
203 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 236 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
204 int InitializeLocked(const ProcessingConfig& config) | 237 int InitializeLocked(const ProcessingConfig& config) |
205 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); | 238 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); |
206 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | 239 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
207 | 240 |
208 // Capture-side exclusive methods possibly running APM in a multi-threaded | 241 // Capture-side exclusive methods possibly running APM in a multi-threaded |
209 // manner that are called with the render lock already acquired. | 242 // manner that are called with the render lock already acquired. |
210 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | 243 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
211 bool output_copy_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | |
212 bool is_fwd_processed() const EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | |
213 bool fwd_synthesis_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | |
214 bool fwd_analysis_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | |
215 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); | 244 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); |
216 | 245 |
217 // Render-side exclusive methods possibly running APM in a multi-threaded | 246 // Render-side exclusive methods possibly running APM in a multi-threaded |
218 // manner that are called with the render lock already acquired. | 247 // manner that are called with the render lock already acquired. |
219 // TODO(ekm): Remove once all clients updated to new interface. | 248 // TODO(ekm): Remove once all clients updated to new interface. |
220 int AnalyzeReverseStreamLocked(const float* const* src, | 249 int AnalyzeReverseStreamLocked(const float* const* src, |
221 const StreamConfig& input_config, | 250 const StreamConfig& input_config, |
222 const StreamConfig& output_config) | 251 const StreamConfig& output_config) |
223 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | 252 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
224 bool is_rev_processed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | |
225 bool rev_synthesis_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | |
226 bool rev_analysis_needed() const EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | |
227 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_); | 253 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_); |
228 | 254 |
229 // Debug dump methods that are internal and called without locks. | 255 // Debug dump methods that are internal and called without locks. |
230 // TODO(peah): Make thread safe. | 256 // TODO(peah): Make thread safe. |
231 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 257 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
232 // TODO(andrew): make this more graceful. Ideally we would split this stuff | 258 // TODO(andrew): make this more graceful. Ideally we would split this stuff |
233 // out into a separate class with an "enabled" and "disabled" implementation. | 259 // out into a separate class with an "enabled" and "disabled" implementation. |
234 static int WriteMessageToDebugFile(FileWrapper* debug_file, | 260 static int WriteMessageToDebugFile(FileWrapper* debug_file, |
235 int64_t* filesize_limit_bytes, | 261 int64_t* filesize_limit_bytes, |
236 rtc::CriticalSection* crit_debug, | 262 rtc::CriticalSection* crit_debug, |
(...skipping 10 matching lines...) Expand all Loading... | |
247 rtc::CriticalSection crit_debug_; | 273 rtc::CriticalSection crit_debug_; |
248 | 274 |
249 // Debug dump state. | 275 // Debug dump state. |
250 ApmDebugDumpState debug_dump_; | 276 ApmDebugDumpState debug_dump_; |
251 #endif | 277 #endif |
252 | 278 |
253 // Critical sections. | 279 // Critical sections. |
254 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_); | 280 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_); |
255 rtc::CriticalSection crit_capture_; | 281 rtc::CriticalSection crit_capture_; |
256 | 282 |
283 // Class containing information about what submodules are active. | |
284 ApmSubmoduleStates submodule_states_; | |
285 | |
257 // Structs containing the pointers to the submodules. | 286 // Structs containing the pointers to the submodules. |
258 std::unique_ptr<ApmPublicSubmodules> public_submodules_; | 287 std::unique_ptr<ApmPublicSubmodules> public_submodules_; |
259 std::unique_ptr<ApmPrivateSubmodules> private_submodules_ | 288 std::unique_ptr<ApmPrivateSubmodules> private_submodules_ |
260 GUARDED_BY(crit_capture_); | 289 GUARDED_BY(crit_capture_); |
261 | 290 |
262 // State that is written to while holding both the render and capture locks | 291 // State that is written to while holding both the render and capture locks |
263 // but can be read without any lock being held. | 292 // but can be read without any lock being held. |
264 // As this is only accessed internally of APM, and all internal methods in APM | 293 // As this is only accessed internally of APM, and all internal methods in APM |
265 // either are holding the render or capture locks, this construct is safe as | 294 // either are holding the render or capture locks, this construct is safe as |
266 // it is not possible to read the variables while writing them. | 295 // it is not possible to read the variables while writing them. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 ApmRenderState(); | 364 ApmRenderState(); |
336 ~ApmRenderState(); | 365 ~ApmRenderState(); |
337 std::unique_ptr<AudioConverter> render_converter; | 366 std::unique_ptr<AudioConverter> render_converter; |
338 std::unique_ptr<AudioBuffer> render_audio; | 367 std::unique_ptr<AudioBuffer> render_audio; |
339 } render_ GUARDED_BY(crit_render_); | 368 } render_ GUARDED_BY(crit_render_); |
340 }; | 369 }; |
341 | 370 |
342 } // namespace webrtc | 371 } // namespace webrtc |
343 | 372 |
344 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ | 373 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
OLD | NEW |