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

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: Fixed bad merge 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 struct AudioProcessingImpl::ApmPrivateSubmodules { 147 struct AudioProcessingImpl::ApmPrivateSubmodules {
148 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) 148 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer)
149 : beamformer(beamformer) {} 149 : beamformer(beamformer) {}
150 // Accessed internally from capture or during initialization 150 // Accessed internally from capture or during initialization
151 std::unique_ptr<NonlinearBeamformer> beamformer; 151 std::unique_ptr<NonlinearBeamformer> beamformer;
152 std::unique_ptr<AgcManagerDirect> agc_manager; 152 std::unique_ptr<AgcManagerDirect> agc_manager;
153 std::unique_ptr<LevelController> level_controller; 153 std::unique_ptr<LevelController> level_controller;
154 }; 154 };
155 155
156 AudioProcessing* AudioProcessing::Create() { 156 AudioProcessing* AudioProcessing::Create() {
157 Config config; 157 webrtc::Config config;
158 return Create(config, nullptr); 158 return Create(config, nullptr);
159 } 159 }
160 160
161 AudioProcessing* AudioProcessing::Create(const Config& config) { 161 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) {
162 return Create(config, nullptr); 162 return Create(config, nullptr);
163 } 163 }
164 164
165 AudioProcessing* AudioProcessing::Create(const Config& config, 165 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config,
166 NonlinearBeamformer* beamformer) { 166 NonlinearBeamformer* beamformer) {
167 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer); 167 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer);
168 if (apm->Initialize() != kNoError) { 168 if (apm->Initialize() != kNoError) {
169 delete apm; 169 delete apm;
170 apm = nullptr; 170 apm = nullptr;
171 } 171 }
172 172
173 return apm; 173 return apm;
174 } 174 }
175 175
176 AudioProcessingImpl::AudioProcessingImpl(const Config& config) 176 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
177 : AudioProcessingImpl(config, nullptr) {} 177 : AudioProcessingImpl(config, nullptr) {}
178 178
179 AudioProcessingImpl::AudioProcessingImpl(const Config& config, 179 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
180 NonlinearBeamformer* beamformer) 180 NonlinearBeamformer* beamformer)
181 : public_submodules_(new ApmPublicSubmodules()), 181 : public_submodules_(new ApmPublicSubmodules()),
182 private_submodules_(new ApmPrivateSubmodules(beamformer)), 182 private_submodules_(new ApmPrivateSubmodules(beamformer)),
183 constants_(config.Get<ExperimentalAgc>().startup_min_volume, 183 constants_(config.Get<ExperimentalAgc>().startup_min_volume,
184 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 184 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
185 false), 185 false),
186 #else 186 #else
187 config.Get<ExperimentalAgc>().enabled), 187 config.Get<ExperimentalAgc>().enabled),
188 #endif 188 #endif
189 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 189 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
190 capture_(false, 190 capture_(false,
191 #else 191 #else
192 capture_(config.Get<ExperimentalNs>().enabled, 192 capture_(config.Get<ExperimentalNs>().enabled,
193 #endif 193 #endif
194 config.Get<Beamforming>().array_geometry, 194 config.Get<Beamforming>().array_geometry,
195 config.Get<Beamforming>().target_direction), 195 config.Get<Beamforming>().target_direction),
196 capture_nonlocked_(config.Get<Beamforming>().enabled, 196 capture_nonlocked_(config.Get<Beamforming>().enabled,
197 config.Get<Intelligibility>().enabled, 197 config.Get<Intelligibility>().enabled) {
198 config.Get<LevelControl>().enabled) {
199 { 198 {
200 rtc::CritScope cs_render(&crit_render_); 199 rtc::CritScope cs_render(&crit_render_);
201 rtc::CritScope cs_capture(&crit_capture_); 200 rtc::CritScope cs_capture(&crit_capture_);
202 201
203 public_submodules_->echo_cancellation.reset( 202 public_submodules_->echo_cancellation.reset(
204 new EchoCancellationImpl(&crit_render_, &crit_capture_)); 203 new EchoCancellationImpl(&crit_render_, &crit_capture_));
205 public_submodules_->echo_control_mobile.reset( 204 public_submodules_->echo_control_mobile.reset(
206 new EchoControlMobileImpl(&crit_render_, &crit_capture_)); 205 new EchoControlMobileImpl(&crit_render_, &crit_capture_));
207 public_submodules_->gain_control.reset( 206 public_submodules_->gain_control.reset(
208 new GainControlImpl(&crit_capture_, &crit_capture_)); 207 new GainControlImpl(&crit_capture_, &crit_capture_));
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { 424 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) {
426 capture_nonlocked_.split_rate = kSampleRate16kHz; 425 capture_nonlocked_.split_rate = kSampleRate16kHz;
427 } else { 426 } else {
428 capture_nonlocked_.split_rate = 427 capture_nonlocked_.split_rate =
429 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); 428 capture_nonlocked_.fwd_proc_format.sample_rate_hz();
430 } 429 }
431 430
432 return InitializeLocked(); 431 return InitializeLocked();
433 } 432 }
434 433
435 void AudioProcessingImpl::SetExtraOptions(const Config& config) { 434 void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
435 AudioProcessing::Config config_to_use = config;
436
437 bool config_ok = LevelController::Validate(config_to_use.level_controller);
438 if (!config_ok) {
439 LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
440 << "level_controller: "
441 << LevelController::ToString(config_to_use.level_controller)
442 << std::endl
443 << "Reverting to default parameter set";
444 config_to_use.level_controller = AudioProcessing::Config::LevelController();
445 }
446
447 // Run in a single-threaded manner when applying the settings.
448 rtc::CritScope cs_render(&crit_render_);
449 rtc::CritScope cs_capture(&crit_capture_);
450
451 if (config.level_controller.enabled !=
452 capture_nonlocked_.level_controller_enabled) {
453 InitializeLevelController();
454 LOG(LS_INFO) << "Level controller activated: "
455 << capture_nonlocked_.level_controller_enabled;
456 capture_nonlocked_.level_controller_enabled =
457 config.level_controller.enabled;
458 }
459 }
460
461 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
436 // Run in a single-threaded manner when setting the extra options. 462 // Run in a single-threaded manner when setting the extra options.
437 rtc::CritScope cs_render(&crit_render_); 463 rtc::CritScope cs_render(&crit_render_);
438 rtc::CritScope cs_capture(&crit_capture_); 464 rtc::CritScope cs_capture(&crit_capture_);
439 465
440 public_submodules_->echo_cancellation->SetExtraOptions(config); 466 public_submodules_->echo_cancellation->SetExtraOptions(config);
441 467
442 if (capture_.transient_suppressor_enabled != 468 if (capture_.transient_suppressor_enabled !=
443 config.Get<ExperimentalNs>().enabled) { 469 config.Get<ExperimentalNs>().enabled) {
444 capture_.transient_suppressor_enabled = 470 capture_.transient_suppressor_enabled =
445 config.Get<ExperimentalNs>().enabled; 471 config.Get<ExperimentalNs>().enabled;
446 InitializeTransient(); 472 InitializeTransient();
447 } 473 }
448 474
449 if (capture_nonlocked_.level_controller_enabled !=
450 config.Get<LevelControl>().enabled) {
451 capture_nonlocked_.level_controller_enabled =
452 config.Get<LevelControl>().enabled;
453 LOG(LS_INFO) << "Level controller activated: "
454 << config.Get<LevelControl>().enabled;
455
456 InitializeLevelController();
457 }
458
459 #if WEBRTC_INTELLIGIBILITY_ENHANCER 475 #if WEBRTC_INTELLIGIBILITY_ENHANCER
460 if(capture_nonlocked_.intelligibility_enabled != 476 if(capture_nonlocked_.intelligibility_enabled !=
461 config.Get<Intelligibility>().enabled) { 477 config.Get<Intelligibility>().enabled) {
462 capture_nonlocked_.intelligibility_enabled = 478 capture_nonlocked_.intelligibility_enabled =
463 config.Get<Intelligibility>().enabled; 479 config.Get<Intelligibility>().enabled;
464 InitializeIntelligibility(); 480 InitializeIntelligibility();
465 } 481 }
466 #endif 482 #endif
467 483
468 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 484 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 fwd_proc_format(kSampleRate16kHz), 1577 fwd_proc_format(kSampleRate16kHz),
1562 split_rate(kSampleRate16kHz) {} 1578 split_rate(kSampleRate16kHz) {}
1563 1579
1564 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; 1580 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
1565 1581
1566 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; 1582 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
1567 1583
1568 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; 1584 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
1569 1585
1570 } // namespace webrtc 1586 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698