Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.h

Issue 2304123002: Cleaned up and revised the handling of resampling and bandsplitting in APM and (Closed)
Patch Set: Typo correction Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 LevelEstimator* level_estimator() const override; 120 LevelEstimator* level_estimator() const override;
121 NoiseSuppression* noise_suppression() const override; 121 NoiseSuppression* noise_suppression() const override;
122 VoiceDetection* voice_detection() const override; 122 VoiceDetection* voice_detection() const override;
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 class ApmSubmoduleStates;
hlundin-webrtc 2016/09/06 10:41:32 I'm not fond of forward-declaring private subclass
peah-webrtc 2016/09/07 06:28:11 Done.
130 struct ApmPublicSubmodules; 131 struct ApmPublicSubmodules;
131 struct ApmPrivateSubmodules; 132 struct ApmPrivateSubmodules;
132 133
133 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 134 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
134 // State for the debug dump. 135 // State for the debug dump.
135 struct ApmDebugDumpThreadState { 136 struct ApmDebugDumpThreadState {
136 ApmDebugDumpThreadState(); 137 ApmDebugDumpThreadState();
137 ~ApmDebugDumpThreadState(); 138 ~ApmDebugDumpThreadState();
138 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message. 139 std::unique_ptr<audioproc::Event> event_msg; // Protobuf message.
139 std::string event_str; // Memory for protobuf serialization. 140 std::string event_str; // Memory for protobuf serialization.
(...skipping 13 matching lines...) Expand all
153 ApmDebugDumpThreadState capture; 154 ApmDebugDumpThreadState capture;
154 }; 155 };
155 #endif 156 #endif
156 157
157 // Method for modifying the formats struct that are called from both 158 // Method for modifying the formats struct that are called from both
158 // the render and capture threads. The check for whether modifications 159 // the render and capture threads. The check for whether modifications
159 // are needed is done while holding the render lock only, thereby avoiding 160 // are needed is done while holding the render lock only, thereby avoiding
160 // that the capture thread blocks the render thread. 161 // that the capture thread blocks the render thread.
161 // The struct is modified in a single-threaded manner by holding both the 162 // The struct is modified in a single-threaded manner by holding both the
162 // render and capture locks. 163 // render and capture locks.
163 int MaybeInitialize(const ProcessingConfig& config) 164 int MaybeInitialize(const ProcessingConfig& config, bool force_initialization)
164 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 165 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
165 166
166 int MaybeInitializeRender(const ProcessingConfig& processing_config) 167 int MaybeInitializeRender(const ProcessingConfig& processing_config)
167 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 168 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
168 169
169 int MaybeInitializeCapture(const ProcessingConfig& processing_config) 170 int MaybeInitializeCapture(const ProcessingConfig& processing_config,
171 bool force_initialization)
170 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 172 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
171 173
172 // Method for checking for the need of conversion. Accesses the formats 174 // 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 175 // Returns a bool indicating whether the state had changed.
174 // was added as it currently anyway is always called in that manner. 176 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 177
179 // Methods requiring APM running in a single-threaded manner. 178 // Methods requiring APM running in a single-threaded manner.
180 // Are called with both the render and capture locks already 179 // Are called with both the render and capture locks already
181 // acquired. 180 // acquired.
182 void InitializeExperimentalAgc() 181 void InitializeExperimentalAgc()
183 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 182 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
184 void InitializeTransient() 183 void InitializeTransient()
185 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 184 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
186 void InitializeBeamformer() 185 void InitializeBeamformer()
187 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 186 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
(...skipping 13 matching lines...) Expand all
201 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 200 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
202 void InitializeEchoControlMobile() 201 void InitializeEchoControlMobile()
203 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 202 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
204 int InitializeLocked(const ProcessingConfig& config) 203 int InitializeLocked(const ProcessingConfig& config)
205 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 204 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
206 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 205 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
207 206
208 // Capture-side exclusive methods possibly running APM in a multi-threaded 207 // Capture-side exclusive methods possibly running APM in a multi-threaded
209 // manner that are called with the render lock already acquired. 208 // manner that are called with the render lock already acquired.
210 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 209 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_); 210 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
216 211
217 // Render-side exclusive methods possibly running APM in a multi-threaded 212 // Render-side exclusive methods possibly running APM in a multi-threaded
218 // manner that are called with the render lock already acquired. 213 // manner that are called with the render lock already acquired.
219 // TODO(ekm): Remove once all clients updated to new interface. 214 // TODO(ekm): Remove once all clients updated to new interface.
220 int AnalyzeReverseStreamLocked(const float* const* src, 215 int AnalyzeReverseStreamLocked(const float* const* src,
221 const StreamConfig& input_config, 216 const StreamConfig& input_config,
222 const StreamConfig& output_config) 217 const StreamConfig& output_config)
223 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 218 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_); 219 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
228 220
229 // Debug dump methods that are internal and called without locks. 221 // Debug dump methods that are internal and called without locks.
230 // TODO(peah): Make thread safe. 222 // TODO(peah): Make thread safe.
231 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 223 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
232 // TODO(andrew): make this more graceful. Ideally we would split this stuff 224 // TODO(andrew): make this more graceful. Ideally we would split this stuff
233 // out into a separate class with an "enabled" and "disabled" implementation. 225 // out into a separate class with an "enabled" and "disabled" implementation.
234 static int WriteMessageToDebugFile(FileWrapper* debug_file, 226 static int WriteMessageToDebugFile(FileWrapper* debug_file,
235 int64_t* filesize_limit_bytes, 227 int64_t* filesize_limit_bytes,
236 rtc::CriticalSection* crit_debug, 228 rtc::CriticalSection* crit_debug,
(...skipping 10 matching lines...) Expand all
247 rtc::CriticalSection crit_debug_; 239 rtc::CriticalSection crit_debug_;
248 240
249 // Debug dump state. 241 // Debug dump state.
250 ApmDebugDumpState debug_dump_; 242 ApmDebugDumpState debug_dump_;
251 #endif 243 #endif
252 244
253 // Critical sections. 245 // Critical sections.
254 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_); 246 rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_);
255 rtc::CriticalSection crit_capture_; 247 rtc::CriticalSection crit_capture_;
256 248
249 // Class containing information about what submodules are active.
250 std::unique_ptr<ApmSubmoduleStates> submodule_states_;
hlundin-webrtc 2016/09/06 10:41:32 As said above, don't use std::unique_ptr. Let it b
peah-webrtc 2016/09/07 06:28:11 Sounds good! Done.
251
257 // Structs containing the pointers to the submodules. 252 // Structs containing the pointers to the submodules.
258 std::unique_ptr<ApmPublicSubmodules> public_submodules_; 253 std::unique_ptr<ApmPublicSubmodules> public_submodules_;
259 std::unique_ptr<ApmPrivateSubmodules> private_submodules_ 254 std::unique_ptr<ApmPrivateSubmodules> private_submodules_
260 GUARDED_BY(crit_capture_); 255 GUARDED_BY(crit_capture_);
261 256
262 // State that is written to while holding both the render and capture locks 257 // State that is written to while holding both the render and capture locks
263 // but can be read without any lock being held. 258 // but can be read without any lock being held.
264 // As this is only accessed internally of APM, and all internal methods in APM 259 // 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 260 // 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. 261 // it is not possible to read the variables while writing them.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 ApmRenderState(); 330 ApmRenderState();
336 ~ApmRenderState(); 331 ~ApmRenderState();
337 std::unique_ptr<AudioConverter> render_converter; 332 std::unique_ptr<AudioConverter> render_converter;
338 std::unique_ptr<AudioBuffer> render_audio; 333 std::unique_ptr<AudioBuffer> render_audio;
339 } render_ GUARDED_BY(crit_render_); 334 } render_ GUARDED_BY(crit_render_);
340 }; 335 };
341 336
342 } // namespace webrtc 337 } // namespace webrtc
343 338
344 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ 339 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698