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

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

Issue 2335633002: This CL renames variables and method and removes some one-line methods inside the APM (Closed)
Patch Set: Changes in response to reviewer comments 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 29 matching lines...) Expand all
40 40
41 class AudioProcessingImpl : public AudioProcessing { 41 class AudioProcessingImpl : public AudioProcessing {
42 public: 42 public:
43 // Methods forcing APM to run in a single-threaded manner. 43 // Methods forcing APM to run in a single-threaded manner.
44 // Acquires both the render and capture locks. 44 // Acquires both the render and capture locks.
45 explicit AudioProcessingImpl(const Config& config); 45 explicit AudioProcessingImpl(const Config& config);
46 // AudioProcessingImpl takes ownership of beamformer. 46 // AudioProcessingImpl takes ownership of beamformer.
47 AudioProcessingImpl(const Config& config, NonlinearBeamformer* beamformer); 47 AudioProcessingImpl(const Config& config, NonlinearBeamformer* beamformer);
48 ~AudioProcessingImpl() override; 48 ~AudioProcessingImpl() override;
49 int Initialize() override; 49 int Initialize() override;
50 int Initialize(int input_sample_rate_hz, 50 int Initialize(int capture_input_sample_rate_hz,
51 int output_sample_rate_hz, 51 int capture_output_sample_rate_hz,
52 int reverse_sample_rate_hz, 52 int render_sample_rate_hz,
53 ChannelLayout input_layout, 53 ChannelLayout capture_input_layout,
54 ChannelLayout output_layout, 54 ChannelLayout capture_output_layout,
55 ChannelLayout reverse_layout) override; 55 ChannelLayout render_input_layout) override;
56 int Initialize(const ProcessingConfig& processing_config) override; 56 int Initialize(const ProcessingConfig& processing_config) override;
57 void SetExtraOptions(const Config& config) override; 57 void SetExtraOptions(const Config& config) override;
58 void UpdateHistogramsOnCallEnd() override; 58 void UpdateHistogramsOnCallEnd() override;
59 int StartDebugRecording(const char filename[kMaxFilenameSize], 59 int StartDebugRecording(const char filename[kMaxFilenameSize],
60 int64_t max_log_size_bytes) override; 60 int64_t max_log_size_bytes) override;
61 int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override; 61 int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override;
62 62
63 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; 63 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override;
64 int StopDebugRecording() override; 64 int StopDebugRecording() override;
65 65
(...skipping 18 matching lines...) Expand all
84 void set_stream_key_pressed(bool key_pressed) override; 84 void set_stream_key_pressed(bool key_pressed) override;
85 85
86 // Render-side exclusive methods possibly running APM in a 86 // Render-side exclusive methods possibly running APM in a
87 // multi-threaded manner. Acquire the render lock. 87 // multi-threaded manner. Acquire the render lock.
88 int ProcessReverseStream(AudioFrame* frame) override; 88 int ProcessReverseStream(AudioFrame* frame) override;
89 int AnalyzeReverseStream(const float* const* data, 89 int AnalyzeReverseStream(const float* const* data,
90 size_t samples_per_channel, 90 size_t samples_per_channel,
91 int sample_rate_hz, 91 int sample_rate_hz,
92 ChannelLayout layout) override; 92 ChannelLayout layout) override;
93 int ProcessReverseStream(const float* const* src, 93 int ProcessReverseStream(const float* const* src,
94 const StreamConfig& reverse_input_config, 94 const StreamConfig& input_config,
95 const StreamConfig& reverse_output_config, 95 const StreamConfig& output_config,
96 float* const* dest) override; 96 float* const* dest) override;
97 97
98 // Methods only accessed from APM submodules or 98 // Methods only accessed from APM submodules or
99 // from AudioProcessing tests in a single-threaded manner. 99 // from AudioProcessing tests in a single-threaded manner.
100 // Hence there is no need for locks in these. 100 // Hence there is no need for locks in these.
101 int proc_sample_rate_hz() const override; 101 int proc_sample_rate_hz() const override;
102 int proc_split_sample_rate_hz() const override; 102 int proc_split_sample_rate_hz() const override;
103 size_t num_input_channels() const override; 103 size_t num_input_channels() const override;
104 size_t num_proc_channels() const override; 104 size_t num_proc_channels() const override;
105 size_t num_output_channels() const override; 105 size_t num_output_channels() const override;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 bool force_initialization) 205 bool force_initialization)
206 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 206 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
207 207
208 // Method for updating the state keeping track of the active submodules. 208 // Method for updating the state keeping track of the active submodules.
209 // Returns a bool indicating whether the state has changed. 209 // Returns a bool indicating whether the state has changed.
210 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 210 bool UpdateActiveSubmoduleStates() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
211 211
212 // Methods requiring APM running in a single-threaded manner. 212 // Methods requiring APM running in a single-threaded manner.
213 // Are called with both the render and capture locks already 213 // Are called with both the render and capture locks already
214 // acquired. 214 // acquired.
215 void InitializeExperimentalAgc()
216 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
217 void InitializeTransient() 215 void InitializeTransient()
218 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 216 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
219 void InitializeBeamformer() 217 void InitializeBeamformer()
220 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 218 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
221 void InitializeIntelligibility() 219 void InitializeIntelligibility()
222 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 220 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
223 void InitializeHighPassFilter()
224 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
225 void InitializeNoiseSuppression()
226 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
227 void InitializeLevelEstimator()
228 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
229 void InitializeVoiceDetection()
230 EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
231 void InitializeEchoCanceller()
232 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
233 void InitializeGainController()
234 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
235 void InitializeEchoControlMobile()
236 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
237 int InitializeLocked(const ProcessingConfig& config) 221 int InitializeLocked(const ProcessingConfig& config)
238 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); 222 EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
239 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 223 void InitializeLevelController() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
240 224
241 // Capture-side exclusive methods possibly running APM in a multi-threaded 225 // Capture-side exclusive methods possibly running APM in a multi-threaded
242 // manner that are called with the render lock already acquired. 226 // manner that are called with the render lock already acquired.
243 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 227 int ProcessCaptureStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
244 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); 228 void MaybeUpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
245 229
246 // Render-side exclusive methods possibly running APM in a multi-threaded 230 // Render-side exclusive methods possibly running APM in a multi-threaded
247 // manner that are called with the render lock already acquired. 231 // manner that are called with the render lock already acquired.
248 // TODO(ekm): Remove once all clients updated to new interface. 232 // TODO(ekm): Remove once all clients updated to new interface.
249 int AnalyzeReverseStreamLocked(const float* const* src, 233 int AnalyzeReverseStreamLocked(const float* const* src,
250 const StreamConfig& input_config, 234 const StreamConfig& input_config,
251 const StreamConfig& output_config) 235 const StreamConfig& output_config)
252 EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 236 EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
253 int ProcessReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_); 237 int ProcessRenderStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
254 238
255 // Debug dump methods that are internal and called without locks. 239 // Debug dump methods that are internal and called without locks.
256 // TODO(peah): Make thread safe. 240 // TODO(peah): Make thread safe.
257 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 241 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
258 // TODO(andrew): make this more graceful. Ideally we would split this stuff 242 // TODO(andrew): make this more graceful. Ideally we would split this stuff
259 // out into a separate class with an "enabled" and "disabled" implementation. 243 // out into a separate class with an "enabled" and "disabled" implementation.
260 static int WriteMessageToDebugFile(FileWrapper* debug_file, 244 static int WriteMessageToDebugFile(FileWrapper* debug_file,
261 int64_t* filesize_limit_bytes, 245 int64_t* filesize_limit_bytes,
262 rtc::CriticalSection* crit_debug, 246 rtc::CriticalSection* crit_debug,
263 ApmDebugDumpThreadState* debug_state); 247 ApmDebugDumpThreadState* debug_state);
(...skipping 29 matching lines...) Expand all
293 // As this is only accessed internally of APM, and all internal methods in APM 277 // As this is only accessed internally of APM, and all internal methods in APM
294 // either are holding the render or capture locks, this construct is safe as 278 // either are holding the render or capture locks, this construct is safe as
295 // it is not possible to read the variables while writing them. 279 // it is not possible to read the variables while writing them.
296 struct ApmFormatState { 280 struct ApmFormatState {
297 ApmFormatState() 281 ApmFormatState()
298 : // Format of processing streams at input/output call sites. 282 : // Format of processing streams at input/output call sites.
299 api_format({{{kSampleRate16kHz, 1, false}, 283 api_format({{{kSampleRate16kHz, 1, false},
300 {kSampleRate16kHz, 1, false}, 284 {kSampleRate16kHz, 1, false},
301 {kSampleRate16kHz, 1, false}, 285 {kSampleRate16kHz, 1, false},
302 {kSampleRate16kHz, 1, false}}}), 286 {kSampleRate16kHz, 1, false}}}),
303 rev_proc_format(kSampleRate16kHz, 1) {} 287 render_processing_format(kSampleRate16kHz, 1) {}
304 ProcessingConfig api_format; 288 ProcessingConfig api_format;
305 StreamConfig rev_proc_format; 289 StreamConfig render_processing_format;
306 } formats_; 290 } formats_;
307 291
308 // APM constants. 292 // APM constants.
309 const struct ApmConstants { 293 const struct ApmConstants {
310 ApmConstants(int agc_startup_min_volume, bool use_experimental_agc) 294 ApmConstants(int agc_startup_min_volume, bool use_experimental_agc)
311 : // Format of processing streams at input/output call sites. 295 : // Format of processing streams at input/output call sites.
312 agc_startup_min_volume(agc_startup_min_volume), 296 agc_startup_min_volume(agc_startup_min_volume),
313 use_experimental_agc(use_experimental_agc) {} 297 use_experimental_agc(use_experimental_agc) {}
314 int agc_startup_min_volume; 298 int agc_startup_min_volume;
315 bool use_experimental_agc; 299 bool use_experimental_agc;
316 } constants_; 300 } constants_;
317 301
318 struct ApmCaptureState { 302 struct ApmCaptureState {
319 ApmCaptureState(bool transient_suppressor_enabled, 303 ApmCaptureState(bool transient_suppressor_enabled,
320 const std::vector<Point>& array_geometry, 304 const std::vector<Point>& array_geometry,
321 SphericalPointf target_direction); 305 SphericalPointf target_direction);
322 ~ApmCaptureState(); 306 ~ApmCaptureState();
323 int aec_system_delay_jumps; 307 int aec_system_delay_jumps;
324 int delay_offset_ms; 308 int delay_offset_ms;
325 bool was_stream_delay_set; 309 bool was_stream_delay_set;
326 int last_stream_delay_ms; 310 int last_stream_delay_ms;
327 int last_aec_system_delay_ms; 311 int last_aec_system_delay_ms;
328 int stream_delay_jumps; 312 int stream_delay_jumps;
329 bool output_will_be_muted; 313 bool output_will_be_muted;
330 bool key_pressed; 314 bool key_pressed;
331 bool transient_suppressor_enabled; 315 bool transient_suppressor_enabled;
332 std::vector<Point> array_geometry; 316 std::vector<Point> array_geometry;
333 SphericalPointf target_direction; 317 SphericalPointf target_direction;
334 std::unique_ptr<AudioBuffer> capture_audio; 318 std::unique_ptr<AudioBuffer> capture_audio;
335 // Only the rate and samples fields of fwd_proc_format_ are used because the 319 // Only the rate and samples fields of capture_processing_format_ are used
336 // forward processing number of channels is mutable and is tracked by the 320 // because the capture processing number of channels is mutable and is
337 // capture_audio_. 321 // tracked by the capture_audio_.
338 StreamConfig fwd_proc_format; 322 StreamConfig capture_processing_format;
339 int split_rate; 323 int split_rate;
340 } capture_ GUARDED_BY(crit_capture_); 324 } capture_ GUARDED_BY(crit_capture_);
341 325
342 struct ApmCaptureNonLockedState { 326 struct ApmCaptureNonLockedState {
343 ApmCaptureNonLockedState(bool beamformer_enabled, 327 ApmCaptureNonLockedState(bool beamformer_enabled,
344 bool intelligibility_enabled, 328 bool intelligibility_enabled,
345 bool level_controller_enabled) 329 bool level_controller_enabled)
346 : fwd_proc_format(kSampleRate16kHz), 330 : capture_processing_format(kSampleRate16kHz),
347 split_rate(kSampleRate16kHz), 331 split_rate(kSampleRate16kHz),
348 stream_delay_ms(0), 332 stream_delay_ms(0),
349 beamformer_enabled(beamformer_enabled), 333 beamformer_enabled(beamformer_enabled),
350 intelligibility_enabled(intelligibility_enabled), 334 intelligibility_enabled(intelligibility_enabled),
351 level_controller_enabled(level_controller_enabled) {} 335 level_controller_enabled(level_controller_enabled) {}
352 // Only the rate and samples fields of fwd_proc_format_ are used because the 336 // Only the rate and samples fields of capture_processing_format_ are used
353 // forward processing number of channels is mutable and is tracked by the 337 // because the forward processing number of channels is mutable and is
354 // capture_audio_. 338 // tracked by the capture_audio_.
355 StreamConfig fwd_proc_format; 339 StreamConfig capture_processing_format;
356 int split_rate; 340 int split_rate;
357 int stream_delay_ms; 341 int stream_delay_ms;
358 bool beamformer_enabled; 342 bool beamformer_enabled;
359 bool intelligibility_enabled; 343 bool intelligibility_enabled;
360 bool level_controller_enabled; 344 bool level_controller_enabled;
361 } capture_nonlocked_; 345 } capture_nonlocked_;
362 346
363 struct ApmRenderState { 347 struct ApmRenderState {
364 ApmRenderState(); 348 ApmRenderState();
365 ~ApmRenderState(); 349 ~ApmRenderState();
366 std::unique_ptr<AudioConverter> render_converter; 350 std::unique_ptr<AudioConverter> render_converter;
367 std::unique_ptr<AudioBuffer> render_audio; 351 std::unique_ptr<AudioBuffer> render_audio;
368 } render_ GUARDED_BY(crit_render_); 352 } render_ GUARDED_BY(crit_render_);
369 }; 353 };
370 354
371 } // namespace webrtc 355 } // namespace webrtc
372 356
373 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ 357 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698