Pass Environment to echo controller factory
When echo controller factories are updated, it would be possible to pass Environment into EchoCanceller3 and thus rely on propagated field trials. Bug: webrtc:369904700 Change-Id: Iba9c04edbaab23277874234bd289e2c37625b1c8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/372040 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Sam Zackrisson <saza@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43614}
This commit is contained in:
parent
fab4992f3d
commit
a5d2906206
@ -146,7 +146,11 @@ rtc_library("aec3_factory") {
|
||||
rtc_source_set("echo_control") {
|
||||
visibility = [ "*" ]
|
||||
sources = [ "echo_control.h" ]
|
||||
deps = [ "../../rtc_base:checks" ]
|
||||
deps = [
|
||||
"../../rtc_base:checks",
|
||||
"../environment",
|
||||
"//third_party/abseil-cpp/absl/base:nullability",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_source_set("echo_detector_creator") {
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -64,11 +66,25 @@ class EchoControl {
|
||||
// Interface for a factory that creates EchoControllers.
|
||||
class EchoControlFactory {
|
||||
public:
|
||||
virtual ~EchoControlFactory() = default;
|
||||
|
||||
// TODO: bugs.webrtc.org/369904700 - Make pure virtual when implemented by
|
||||
// all derived classes.
|
||||
virtual absl::Nonnull<std::unique_ptr<EchoControl>> Create(
|
||||
const Environment& env,
|
||||
int sample_rate_hz,
|
||||
int num_render_channels,
|
||||
int num_capture_channels) {
|
||||
return Create(sample_rate_hz, num_render_channels, num_capture_channels);
|
||||
}
|
||||
|
||||
// TODO: bugs.webrtc.org/369904700 - Delete when implementations are removed
|
||||
// from the derived classes.
|
||||
virtual std::unique_ptr<EchoControl> Create(int sample_rate_hz,
|
||||
int num_render_channels,
|
||||
int num_capture_channels) = 0;
|
||||
|
||||
virtual ~EchoControlFactory() = default;
|
||||
int num_capture_channels) {
|
||||
RTC_CHECK_NOTREACHED();
|
||||
}
|
||||
};
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
@ -1888,7 +1888,8 @@ void AudioProcessingImpl::InitializeEchoController() {
|
||||
// Create and activate the echo controller.
|
||||
if (echo_control_factory_) {
|
||||
submodules_.echo_controller = echo_control_factory_->Create(
|
||||
proc_sample_rate_hz(), num_reverse_channels(), num_proc_channels());
|
||||
env_, proc_sample_rate_hz(), num_reverse_channels(),
|
||||
num_proc_channels());
|
||||
RTC_DCHECK(submodules_.echo_controller);
|
||||
} else {
|
||||
EchoCanceller3Config config;
|
||||
|
||||
@ -64,7 +64,8 @@ class MockEchoControlFactory : public EchoControlFactory {
|
||||
MockEchoControlFactory() : next_mock_(std::make_unique<MockEchoControl>()) {}
|
||||
// Returns a pointer to the next MockEchoControl that this factory creates.
|
||||
MockEchoControl* GetNext() const { return next_mock_.get(); }
|
||||
std::unique_ptr<EchoControl> Create(int /* sample_rate_hz */,
|
||||
std::unique_ptr<EchoControl> Create(const Environment& /* env */,
|
||||
int /* sample_rate_hz */,
|
||||
int /* num_render_channels */,
|
||||
int /* num_capture_channels */) override {
|
||||
std::unique_ptr<EchoControl> mock = std::move(next_mock_);
|
||||
|
||||
@ -68,6 +68,9 @@ ABSL_FLAG(bool,
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::WithoutArgs;
|
||||
|
||||
// All sample rates used by APM internally during processing. Other input /
|
||||
// output rates are resampled to / from one of these.
|
||||
const int kProcessSampleRates[] = {16000, 32000, 48000};
|
||||
@ -2460,8 +2463,6 @@ constexpr void Toggle(bool& b) {
|
||||
b ^= true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(RuntimeSettingTest, TestDefaultCtor) {
|
||||
auto s = AudioProcessing::RuntimeSetting();
|
||||
EXPECT_EQ(AudioProcessing::RuntimeSetting::Type::kNotSpecified, s.type());
|
||||
@ -2573,28 +2574,25 @@ TEST(ApmConfiguration, PreProcessingReceivesRuntimeSettings) {
|
||||
audio.data.data());
|
||||
}
|
||||
|
||||
class MyEchoControlFactory : public EchoControlFactory {
|
||||
class MockEchoControlFactory : public EchoControlFactory {
|
||||
public:
|
||||
std::unique_ptr<EchoControl> Create(int /* sample_rate_hz */) {
|
||||
auto ec = new test::MockEchoControl();
|
||||
EXPECT_CALL(*ec, AnalyzeRender(::testing::_)).Times(1);
|
||||
EXPECT_CALL(*ec, AnalyzeCapture(::testing::_)).Times(2);
|
||||
EXPECT_CALL(*ec, ProcessCapture(::testing::_, ::testing::_, ::testing::_))
|
||||
.Times(2);
|
||||
return std::unique_ptr<EchoControl>(ec);
|
||||
}
|
||||
|
||||
std::unique_ptr<EchoControl> Create(int sample_rate_hz,
|
||||
int /* num_render_channels */,
|
||||
int /* num_capture_channels */) {
|
||||
return Create(sample_rate_hz);
|
||||
}
|
||||
MOCK_METHOD(std::unique_ptr<EchoControl>,
|
||||
Create,
|
||||
(const Environment&, int, int, int),
|
||||
(override));
|
||||
};
|
||||
|
||||
TEST(ApmConfiguration, EchoControlInjection) {
|
||||
// Verify that apm uses an injected echo controller if one is provided.
|
||||
std::unique_ptr<EchoControlFactory> echo_control_factory(
|
||||
new MyEchoControlFactory());
|
||||
auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
|
||||
EXPECT_CALL(*echo_control_factory, Create(_, _, _, _))
|
||||
.WillOnce(WithoutArgs([] {
|
||||
auto ec = std::make_unique<test::MockEchoControl>();
|
||||
EXPECT_CALL(*ec, AnalyzeRender).Times(1);
|
||||
EXPECT_CALL(*ec, AnalyzeCapture).Times(2);
|
||||
EXPECT_CALL(*ec, ProcessCapture(_, _, _)).Times(2);
|
||||
return ec;
|
||||
}));
|
||||
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingBuilder()
|
||||
@ -3417,4 +3415,5 @@ TEST(ApmAnalyzeReverseStreamFormatTest, AnalyzeReverseStream) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user