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

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

Issue 2292863002: Introduced new scheme for controlling the functionality inside the audio processing module (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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 int ClosestHigherNativeRate(int min_proc_rate) { 108 int ClosestHigherNativeRate(int min_proc_rate) {
109 for (int rate : AudioProcessing::kNativeSampleRatesHz) { 109 for (int rate : AudioProcessing::kNativeSampleRatesHz) {
110 if (rate >= min_proc_rate) { 110 if (rate >= min_proc_rate) {
111 return rate; 111 return rate;
112 } 112 }
113 } 113 }
114 return AudioProcessing::kMaxNativeSampleRateHz; 114 return AudioProcessing::kMaxNativeSampleRateHz;
115 } 115 }
116 116
117 bool ValidateConfig(const AudioProcessing::Config& config) {
118 return webrtc::LevelController::Validate(config.level_controller);
119 }
120
117 } // namespace 121 } // namespace
118 122
123 bool AudioProcessing::Config::Validate() const {
124 return ValidateConfig(*this);
125 }
126
119 // Throughout webrtc, it's assumed that success is represented by zero. 127 // Throughout webrtc, it's assumed that success is represented by zero.
120 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); 128 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
121 129
122 struct AudioProcessingImpl::ApmPublicSubmodules { 130 struct AudioProcessingImpl::ApmPublicSubmodules {
123 ApmPublicSubmodules() {} 131 ApmPublicSubmodules() {}
124 // Accessed externally of APM without any lock acquired. 132 // Accessed externally of APM without any lock acquired.
125 std::unique_ptr<EchoCancellationImpl> echo_cancellation; 133 std::unique_ptr<EchoCancellationImpl> echo_cancellation;
126 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; 134 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
127 std::unique_ptr<GainControlImpl> gain_control; 135 std::unique_ptr<GainControlImpl> gain_control;
128 std::unique_ptr<HighPassFilterImpl> high_pass_filter; 136 std::unique_ptr<HighPassFilterImpl> high_pass_filter;
(...skipping 13 matching lines...) Expand all
142 struct AudioProcessingImpl::ApmPrivateSubmodules { 150 struct AudioProcessingImpl::ApmPrivateSubmodules {
143 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) 151 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer)
144 : beamformer(beamformer) {} 152 : beamformer(beamformer) {}
145 // Accessed internally from capture or during initialization 153 // Accessed internally from capture or during initialization
146 std::unique_ptr<NonlinearBeamformer> beamformer; 154 std::unique_ptr<NonlinearBeamformer> beamformer;
147 std::unique_ptr<AgcManagerDirect> agc_manager; 155 std::unique_ptr<AgcManagerDirect> agc_manager;
148 std::unique_ptr<LevelController> level_controller; 156 std::unique_ptr<LevelController> level_controller;
149 }; 157 };
150 158
151 AudioProcessing* AudioProcessing::Create() { 159 AudioProcessing* AudioProcessing::Create() {
152 Config config; 160 webrtc::Config config;
153 return Create(config, nullptr); 161 return Create(config, nullptr);
154 } 162 }
155 163
156 AudioProcessing* AudioProcessing::Create(const Config& config) { 164 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) {
157 return Create(config, nullptr); 165 return Create(config, nullptr);
158 } 166 }
159 167
160 AudioProcessing* AudioProcessing::Create(const Config& config, 168 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config,
161 NonlinearBeamformer* beamformer) { 169 NonlinearBeamformer* beamformer) {
162 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer); 170 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer);
163 if (apm->Initialize() != kNoError) { 171 if (apm->Initialize() != kNoError) {
164 delete apm; 172 delete apm;
165 apm = nullptr; 173 apm = nullptr;
166 } 174 }
167 175
168 return apm; 176 return apm;
169 } 177 }
170 178
171 AudioProcessingImpl::AudioProcessingImpl(const Config& config) 179 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
172 : AudioProcessingImpl(config, nullptr) {} 180 : AudioProcessingImpl(config, nullptr) {}
173 181
174 AudioProcessingImpl::AudioProcessingImpl(const Config& config, 182 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
175 NonlinearBeamformer* beamformer) 183 NonlinearBeamformer* beamformer)
176 : public_submodules_(new ApmPublicSubmodules()), 184 : public_submodules_(new ApmPublicSubmodules()),
177 private_submodules_(new ApmPrivateSubmodules(beamformer)), 185 private_submodules_(new ApmPrivateSubmodules(beamformer)),
178 constants_(config.Get<ExperimentalAgc>().startup_min_volume, 186 constants_(config.Get<ExperimentalAgc>().startup_min_volume,
179 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 187 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
180 false), 188 false),
181 #else 189 #else
182 config.Get<ExperimentalAgc>().enabled), 190 config.Get<ExperimentalAgc>().enabled),
183 #endif 191 #endif
184 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 192 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
185 capture_(false, 193 capture_(false,
186 #else 194 #else
187 capture_(config.Get<ExperimentalNs>().enabled, 195 capture_(config.Get<ExperimentalNs>().enabled,
188 #endif 196 #endif
189 config.Get<Beamforming>().array_geometry, 197 config.Get<Beamforming>().array_geometry,
190 config.Get<Beamforming>().target_direction), 198 config.Get<Beamforming>().target_direction),
191 capture_nonlocked_(config.Get<Beamforming>().enabled, 199 capture_nonlocked_(config.Get<Beamforming>().enabled,
192 config.Get<Intelligibility>().enabled, 200 config.Get<Intelligibility>().enabled) {
193 config.Get<LevelControl>().enabled) {
194 { 201 {
195 rtc::CritScope cs_render(&crit_render_); 202 rtc::CritScope cs_render(&crit_render_);
196 rtc::CritScope cs_capture(&crit_capture_); 203 rtc::CritScope cs_capture(&crit_capture_);
197 204
198 public_submodules_->echo_cancellation.reset( 205 public_submodules_->echo_cancellation.reset(
199 new EchoCancellationImpl(&crit_render_, &crit_capture_)); 206 new EchoCancellationImpl(&crit_render_, &crit_capture_));
200 public_submodules_->echo_control_mobile.reset( 207 public_submodules_->echo_control_mobile.reset(
201 new EchoControlMobileImpl(&crit_render_, &crit_capture_)); 208 new EchoControlMobileImpl(&crit_render_, &crit_capture_));
202 public_submodules_->gain_control.reset( 209 public_submodules_->gain_control.reset(
203 new GainControlImpl(&crit_capture_, &crit_capture_)); 210 new GainControlImpl(&crit_capture_, &crit_capture_));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { 413 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) {
407 capture_nonlocked_.split_rate = kSampleRate16kHz; 414 capture_nonlocked_.split_rate = kSampleRate16kHz;
408 } else { 415 } else {
409 capture_nonlocked_.split_rate = 416 capture_nonlocked_.split_rate =
410 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); 417 capture_nonlocked_.fwd_proc_format.sample_rate_hz();
411 } 418 }
412 419
413 return InitializeLocked(); 420 return InitializeLocked();
414 } 421 }
415 422
416 void AudioProcessingImpl::SetExtraOptions(const Config& config) { 423 bool AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
424 bool config_ok = config.Validate();
425 RTC_DCHECK(config_ok);
426 if (!config_ok) {
427 return false;
428 }
429
430 // Run in a single-threaded manner when applying the settings.
431 rtc::CritScope cs_render(&crit_render_);
432 rtc::CritScope cs_capture(&crit_capture_);
433
434 if (config.level_controller.enabled !=
435 capture_nonlocked_.level_controller_enabled) {
436 InitializeLevelController();
437 LOG(LS_INFO) << "Level controller activated: "
438 << capture_nonlocked_.level_controller_enabled;
439 capture_nonlocked_.level_controller_enabled =
440 config.level_controller.enabled;
441 }
442
443 return true;
444 }
445
446 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
417 // Run in a single-threaded manner when setting the extra options. 447 // Run in a single-threaded manner when setting the extra options.
418 rtc::CritScope cs_render(&crit_render_); 448 rtc::CritScope cs_render(&crit_render_);
419 rtc::CritScope cs_capture(&crit_capture_); 449 rtc::CritScope cs_capture(&crit_capture_);
420 450
421 public_submodules_->echo_cancellation->SetExtraOptions(config); 451 public_submodules_->echo_cancellation->SetExtraOptions(config);
422 452
423 if (capture_.transient_suppressor_enabled != 453 if (capture_.transient_suppressor_enabled !=
424 config.Get<ExperimentalNs>().enabled) { 454 config.Get<ExperimentalNs>().enabled) {
425 capture_.transient_suppressor_enabled = 455 capture_.transient_suppressor_enabled =
426 config.Get<ExperimentalNs>().enabled; 456 config.Get<ExperimentalNs>().enabled;
427 InitializeTransient(); 457 InitializeTransient();
428 } 458 }
429 459
430 if (capture_nonlocked_.level_controller_enabled !=
431 config.Get<LevelControl>().enabled) {
432 capture_nonlocked_.level_controller_enabled =
433 config.Get<LevelControl>().enabled;
434 LOG(LS_INFO) << "Level controller activated: "
435 << config.Get<LevelControl>().enabled;
436
437 InitializeLevelController();
438 }
439
440 #if WEBRTC_INTELLIGIBILITY_ENHANCER 460 #if WEBRTC_INTELLIGIBILITY_ENHANCER
441 if(capture_nonlocked_.intelligibility_enabled != 461 if(capture_nonlocked_.intelligibility_enabled !=
442 config.Get<Intelligibility>().enabled) { 462 config.Get<Intelligibility>().enabled) {
443 capture_nonlocked_.intelligibility_enabled = 463 capture_nonlocked_.intelligibility_enabled =
444 config.Get<Intelligibility>().enabled; 464 config.Get<Intelligibility>().enabled;
445 InitializeIntelligibility(); 465 InitializeIntelligibility();
446 } 466 }
447 #endif 467 #endif
448 468
449 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 469 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); 1538 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
1519 1539
1520 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1540 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1521 &debug_dump_.num_bytes_left_for_log_, 1541 &debug_dump_.num_bytes_left_for_log_,
1522 &crit_debug_, &debug_dump_.capture)); 1542 &crit_debug_, &debug_dump_.capture));
1523 return kNoError; 1543 return kNoError;
1524 } 1544 }
1525 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1545 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1526 1546
1527 } // namespace webrtc 1547 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698