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

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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 117 } // namespace
118 118
119 bool AudioProcessing::Config::Validate() const {
120 return level_controller.Validate();
121 }
122
119 // Throughout webrtc, it's assumed that success is represented by zero. 123 // Throughout webrtc, it's assumed that success is represented by zero.
120 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); 124 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
121 125
122 struct AudioProcessingImpl::ApmPublicSubmodules { 126 struct AudioProcessingImpl::ApmPublicSubmodules {
123 ApmPublicSubmodules() {} 127 ApmPublicSubmodules() {}
124 // Accessed externally of APM without any lock acquired. 128 // Accessed externally of APM without any lock acquired.
125 std::unique_ptr<EchoCancellationImpl> echo_cancellation; 129 std::unique_ptr<EchoCancellationImpl> echo_cancellation;
126 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile; 130 std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
127 std::unique_ptr<GainControlImpl> gain_control; 131 std::unique_ptr<GainControlImpl> gain_control;
128 std::unique_ptr<HighPassFilterImpl> high_pass_filter; 132 std::unique_ptr<HighPassFilterImpl> high_pass_filter;
(...skipping 13 matching lines...) Expand all
142 struct AudioProcessingImpl::ApmPrivateSubmodules { 146 struct AudioProcessingImpl::ApmPrivateSubmodules {
143 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer) 147 explicit ApmPrivateSubmodules(NonlinearBeamformer* beamformer)
144 : beamformer(beamformer) {} 148 : beamformer(beamformer) {}
145 // Accessed internally from capture or during initialization 149 // Accessed internally from capture or during initialization
146 std::unique_ptr<NonlinearBeamformer> beamformer; 150 std::unique_ptr<NonlinearBeamformer> beamformer;
147 std::unique_ptr<AgcManagerDirect> agc_manager; 151 std::unique_ptr<AgcManagerDirect> agc_manager;
148 std::unique_ptr<LevelController> level_controller; 152 std::unique_ptr<LevelController> level_controller;
149 }; 153 };
150 154
151 AudioProcessing* AudioProcessing::Create() { 155 AudioProcessing* AudioProcessing::Create() {
152 Config config; 156 webrtc::Config config;
153 return Create(config, nullptr); 157 return Create(config, nullptr);
154 } 158 }
155 159
156 AudioProcessing* AudioProcessing::Create(const Config& config) { 160 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) {
157 return Create(config, nullptr); 161 return Create(config, nullptr);
158 } 162 }
159 163
160 AudioProcessing* AudioProcessing::Create(const Config& config, 164 AudioProcessing* AudioProcessing::Create(const webrtc::Config& config,
161 NonlinearBeamformer* beamformer) { 165 NonlinearBeamformer* beamformer) {
162 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer); 166 AudioProcessingImpl* apm = new AudioProcessingImpl(config, beamformer);
163 if (apm->Initialize() != kNoError) { 167 if (apm->Initialize() != kNoError) {
164 delete apm; 168 delete apm;
165 apm = nullptr; 169 apm = nullptr;
166 } 170 }
167 171
168 return apm; 172 return apm;
169 } 173 }
170 174
171 AudioProcessingImpl::AudioProcessingImpl(const Config& config) 175 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
172 : AudioProcessingImpl(config, nullptr) {} 176 : AudioProcessingImpl(config, nullptr) {}
173 177
174 AudioProcessingImpl::AudioProcessingImpl(const Config& config, 178 AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config,
175 NonlinearBeamformer* beamformer) 179 NonlinearBeamformer* beamformer)
176 : public_submodules_(new ApmPublicSubmodules()), 180 : public_submodules_(new ApmPublicSubmodules()),
177 private_submodules_(new ApmPrivateSubmodules(beamformer)), 181 private_submodules_(new ApmPrivateSubmodules(beamformer)),
178 constants_(config.Get<ExperimentalAgc>().startup_min_volume, 182 constants_(config.Get<ExperimentalAgc>().startup_min_volume,
179 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 183 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
180 false), 184 false),
181 #else 185 #else
182 config.Get<ExperimentalAgc>().enabled), 186 config.Get<ExperimentalAgc>().enabled),
183 #endif 187 #endif
184 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 188 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
185 capture_(false, 189 capture_(false,
186 #else 190 #else
187 capture_(config.Get<ExperimentalNs>().enabled, 191 capture_(config.Get<ExperimentalNs>().enabled,
188 #endif 192 #endif
189 config.Get<Beamforming>().array_geometry, 193 config.Get<Beamforming>().array_geometry,
190 config.Get<Beamforming>().target_direction), 194 config.Get<Beamforming>().target_direction),
191 capture_nonlocked_(config.Get<Beamforming>().enabled, 195 capture_nonlocked_(config.Get<Beamforming>().enabled,
192 config.Get<Intelligibility>().enabled, 196 config.Get<Intelligibility>().enabled) {
193 config.Get<LevelControl>().enabled) {
194 { 197 {
195 rtc::CritScope cs_render(&crit_render_); 198 rtc::CritScope cs_render(&crit_render_);
196 rtc::CritScope cs_capture(&crit_capture_); 199 rtc::CritScope cs_capture(&crit_capture_);
197 200
198 public_submodules_->echo_cancellation.reset( 201 public_submodules_->echo_cancellation.reset(
199 new EchoCancellationImpl(&crit_render_, &crit_capture_)); 202 new EchoCancellationImpl(&crit_render_, &crit_capture_));
200 public_submodules_->echo_control_mobile.reset( 203 public_submodules_->echo_control_mobile.reset(
201 new EchoControlMobileImpl(&crit_render_, &crit_capture_)); 204 new EchoControlMobileImpl(&crit_render_, &crit_capture_));
202 public_submodules_->gain_control.reset( 205 public_submodules_->gain_control.reset(
203 new GainControlImpl(&crit_capture_, &crit_capture_)); 206 new GainControlImpl(&crit_capture_, &crit_capture_));
(...skipping 27 matching lines...) Expand all
231 #endif 234 #endif
232 } 235 }
233 236
234 int AudioProcessingImpl::Initialize() { 237 int AudioProcessingImpl::Initialize() {
235 // Run in a single-threaded manner during initialization. 238 // Run in a single-threaded manner during initialization.
236 rtc::CritScope cs_render(&crit_render_); 239 rtc::CritScope cs_render(&crit_render_);
237 rtc::CritScope cs_capture(&crit_capture_); 240 rtc::CritScope cs_capture(&crit_capture_);
238 return InitializeLocked(); 241 return InitializeLocked();
239 } 242 }
240 243
244 bool AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
245 bool config_ok = config.Validate();
246 RTC_DCHECK(config_ok);
247
the sun 2016/08/30 18:05:35 dd
peah-webrtc 2016/08/31 08:08:31 Done.
248 if (!config_ok) {
249 return false;
250 }
251
252 // Run in a single-threaded manner when applying the settings.
253 rtc::CritScope cs_render(&crit_render_);
254 rtc::CritScope cs_capture(&crit_capture_);
255
256 capture_nonlocked_.level_controller_enabled = config.level_controller.enabled;
257 if (capture_nonlocked_.level_controller_enabled) {
the sun 2016/08/30 18:05:35 You could drop the capture_nonlocked_.level_contro
peah-webrtc 2016/08/31 08:08:31 I'm not sure I follow that. Do you mean that I sho
258 InitializeLevelController();
259 }
260 LOG(LS_INFO) << "Level controller activated: "
261 << capture_nonlocked_.level_controller_enabled;
262
263 return true;
264 }
265
241 int AudioProcessingImpl::Initialize(int input_sample_rate_hz, 266 int AudioProcessingImpl::Initialize(int input_sample_rate_hz,
242 int output_sample_rate_hz, 267 int output_sample_rate_hz,
243 int reverse_sample_rate_hz, 268 int reverse_sample_rate_hz,
244 ChannelLayout input_layout, 269 ChannelLayout input_layout,
245 ChannelLayout output_layout, 270 ChannelLayout output_layout,
246 ChannelLayout reverse_layout) { 271 ChannelLayout reverse_layout) {
247 const ProcessingConfig processing_config = { 272 const ProcessingConfig processing_config = {
248 {{input_sample_rate_hz, 273 {{input_sample_rate_hz,
249 ChannelsFromLayout(input_layout), 274 ChannelsFromLayout(input_layout),
250 LayoutHasKeyboard(input_layout)}, 275 LayoutHasKeyboard(input_layout)},
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { 431 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) {
407 capture_nonlocked_.split_rate = kSampleRate16kHz; 432 capture_nonlocked_.split_rate = kSampleRate16kHz;
408 } else { 433 } else {
409 capture_nonlocked_.split_rate = 434 capture_nonlocked_.split_rate =
410 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); 435 capture_nonlocked_.fwd_proc_format.sample_rate_hz();
411 } 436 }
412 437
413 return InitializeLocked(); 438 return InitializeLocked();
414 } 439 }
415 440
416 void AudioProcessingImpl::SetExtraOptions(const Config& config) { 441 void AudioProcessingImpl::SetExtraOptions(const webrtc::Config& config) {
417 // Run in a single-threaded manner when setting the extra options. 442 // Run in a single-threaded manner when setting the extra options.
418 rtc::CritScope cs_render(&crit_render_); 443 rtc::CritScope cs_render(&crit_render_);
419 rtc::CritScope cs_capture(&crit_capture_); 444 rtc::CritScope cs_capture(&crit_capture_);
420 445
421 public_submodules_->echo_cancellation->SetExtraOptions(config); 446 public_submodules_->echo_cancellation->SetExtraOptions(config);
422 447
423 if (capture_.transient_suppressor_enabled != 448 if (capture_.transient_suppressor_enabled !=
424 config.Get<ExperimentalNs>().enabled) { 449 config.Get<ExperimentalNs>().enabled) {
425 capture_.transient_suppressor_enabled = 450 capture_.transient_suppressor_enabled =
426 config.Get<ExperimentalNs>().enabled; 451 config.Get<ExperimentalNs>().enabled;
427 InitializeTransient(); 452 InitializeTransient();
428 } 453 }
429 454
430 if (capture_nonlocked_.level_controller_enabled !=
431 config.Get<LevelControl>().enabled) {
the sun 2016/08/30 18:05:35 Note that the new code won't avoid initializing th
peah-webrtc 2016/08/31 08:08:31 No, that was not intended at all. Great catch!!!
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 455 #if WEBRTC_INTELLIGIBILITY_ENHANCER
441 if(capture_nonlocked_.intelligibility_enabled != 456 if(capture_nonlocked_.intelligibility_enabled !=
442 config.Get<Intelligibility>().enabled) { 457 config.Get<Intelligibility>().enabled) {
443 capture_nonlocked_.intelligibility_enabled = 458 capture_nonlocked_.intelligibility_enabled =
444 config.Get<Intelligibility>().enabled; 459 config.Get<Intelligibility>().enabled;
445 InitializeIntelligibility(); 460 InitializeIntelligibility();
446 } 461 }
447 #endif 462 #endif
448 463
449 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 464 #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); 1533 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config);
1519 1534
1520 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1535 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1521 &debug_dump_.num_bytes_left_for_log_, 1536 &debug_dump_.num_bytes_left_for_log_,
1522 &crit_debug_, &debug_dump_.capture)); 1537 &crit_debug_, &debug_dump_.capture));
1523 return kNoError; 1538 return kNoError;
1524 } 1539 }
1525 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1540 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1526 1541
1527 } // namespace webrtc 1542 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698