EchoControl factory injectable in AudioProcessing.

This CL enables a factory method creating acoustic echo cancellers
that inherit EchoControl to be injected into the audio processing
module. AudioProcessing will call the factory method to create an
instance of the EchoControl subclass when needed. In the event of
sample rate changes, AudioProcessing will recreate the object using
the factory method.

Bug: webrtc:8346
Change-Id: I0c508b4d4cdb35569864cefaa0e3aea2555cc9b9
Reviewed-on: https://webrtc-review.googlesource.com/7742
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20251}
This commit is contained in:
Gustaf Ullberg
2017-10-11 16:29:02 +02:00
committed by Commit Bot
parent 5de6b1a211
commit d8579e0133
5 changed files with 46 additions and 11 deletions

View File

@ -309,24 +309,35 @@ struct AudioProcessingImpl::ApmPrivateSubmodules {
AudioProcessing* AudioProcessing::Create() {
webrtc::Config config;
return Create(config, nullptr, nullptr);
return Create(config, nullptr, rtc::Callback1<EchoControl*, int>(), nullptr);
}
AudioProcessing* AudioProcessing::Create(const webrtc::Config& config) {
return Create(config, nullptr, nullptr);
return Create(config, nullptr, rtc::Callback1<EchoControl*, int>(), nullptr);
}
AudioProcessing* AudioProcessing::Create(const webrtc::Config& config,
NonlinearBeamformer* beamformer) {
return Create(config, nullptr, beamformer);
return Create(config, nullptr, rtc::Callback1<EchoControl*, int>(),
beamformer);
}
AudioProcessing* AudioProcessing::Create(
const webrtc::Config& config,
std::unique_ptr<PostProcessing> capture_post_processor,
NonlinearBeamformer* beamformer) {
return Create(config, std::move(capture_post_processor),
rtc::Callback1<EchoControl*, int>(), beamformer);
}
AudioProcessing* AudioProcessing::Create(
const webrtc::Config& config,
std::unique_ptr<PostProcessing> capture_post_processor,
rtc::Callback1<EchoControl*, int> echo_control_factory,
NonlinearBeamformer* beamformer) {
AudioProcessingImpl* apm = new rtc::RefCountedObject<AudioProcessingImpl>(
config, std::move(capture_post_processor), beamformer);
config, std::move(capture_post_processor), echo_control_factory,
beamformer);
if (apm->Initialize() != kNoError) {
delete apm;
apm = nullptr;
@ -336,13 +347,18 @@ AudioProcessing* AudioProcessing::Create(
}
AudioProcessingImpl::AudioProcessingImpl(const webrtc::Config& config)
: AudioProcessingImpl(config, nullptr, nullptr) {}
: AudioProcessingImpl(config,
nullptr,
rtc::Callback1<EchoControl*, int>(),
nullptr) {}
AudioProcessingImpl::AudioProcessingImpl(
const webrtc::Config& config,
std::unique_ptr<PostProcessing> capture_post_processor,
rtc::Callback1<EchoControl*, int> echo_control_factory,
NonlinearBeamformer* beamformer)
: high_pass_filter_impl_(new HighPassFilterImpl(this)),
echo_control_factory_(echo_control_factory),
submodule_states_(!!capture_post_processor),
public_submodules_(new ApmPublicSubmodules()),
private_submodules_(
@ -679,6 +695,7 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
LOG(LS_INFO) << "Highpass filter activated: "
<< config_.high_pass_filter.enabled;
// TODO(gustaf): Do this outside of APM.
config_ok = EchoCanceller3::Validate(config_.echo_canceller3);
if (!config_ok) {
LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl
@ -689,6 +706,7 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) {
config_.echo_canceller3 = AudioProcessing::Config::EchoCanceller3();
}
// TODO(gustaf): Enable EchoCanceller3 by injection, not configuration.
if (config.echo_canceller3.enabled !=
capture_nonlocked_.echo_canceller3_enabled) {
capture_nonlocked_.echo_canceller3_enabled =
@ -1697,7 +1715,11 @@ void AudioProcessingImpl::InitializeLowCutFilter() {
}
void AudioProcessingImpl::InitializeEchoCanceller3() {
if (capture_nonlocked_.echo_canceller3_enabled) {
if (!echo_control_factory_.empty()) {
private_submodules_->echo_controller.reset(
echo_control_factory_(proc_sample_rate_hz()));
} else if (capture_nonlocked_.echo_canceller3_enabled) {
// TODO(gustaf): Remove once injection is used.
private_submodules_->echo_controller.reset(new EchoCanceller3(
config_.echo_canceller3, proc_sample_rate_hz(), true));
} else {