OLD | NEW |
---|---|
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 Loading... | |
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 { | |
the sun
2016/09/01 13:48:00
Make .cc-local or bake into ApplyConfig().
peah-webrtc
2016/09/02 08:22:00
Done.
| |
120 return webrtc::LevelController::Validate(level_controller); | |
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 Loading... | |
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { | 409 capture_nonlocked_.fwd_proc_format.sample_rate_hz() == kSampleRate48kHz) { |
407 capture_nonlocked_.split_rate = kSampleRate16kHz; | 410 capture_nonlocked_.split_rate = kSampleRate16kHz; |
408 } else { | 411 } else { |
409 capture_nonlocked_.split_rate = | 412 capture_nonlocked_.split_rate = |
410 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); | 413 capture_nonlocked_.fwd_proc_format.sample_rate_hz(); |
411 } | 414 } |
412 | 415 |
413 return InitializeLocked(); | 416 return InitializeLocked(); |
414 } | 417 } |
415 | 418 |
416 void AudioProcessingImpl::SetExtraOptions(const Config& config) { | 419 bool AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { |
420 bool config_ok = config.Validate(); | |
421 RTC_DCHECK(config_ok); | |
422 if (!config_ok) { | |
423 return false; | |
424 } | |
425 | |
426 // Run in a single-threaded manner when applying the settings. | |
427 rtc::CritScope cs_render(&crit_render_); | |
428 rtc::CritScope cs_capture(&crit_capture_); | |
429 | |
430 if (config.level_controller.enabled && | |
the sun
2016/09/01 13:48:00
!=
peah-webrtc
2016/09/02 08:22:00
Done.
| |
431 (!capture_nonlocked_.level_controller_enabled)) { | |
432 InitializeLevelController(); | |
433 LOG(LS_INFO) << "Level controller activated: " | |
434 << capture_nonlocked_.level_controller_enabled; | |
435 } | |
436 capture_nonlocked_.level_controller_enabled = config.level_controller.enabled; | |
the sun
2016/09/01 13:48:00
Move inside the above conditional
peah-webrtc
2016/09/02 08:22:00
Done.
| |
437 | |
438 return true; | |
439 } | |
440 | |
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) { | |
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 Loading... | |
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 |
OLD | NEW |