From 5cb8439d8e7312947ddafc667103b2ca99f33983 Mon Sep 17 00:00:00 2001 From: Li-Yu Yu Date: Wed, 15 Nov 2023 22:33:23 +0000 Subject: [PATCH] can_use_dsp_aec: Fix not checking both bits for DSP AEC BUG=b:311156968 TEST=bazel test //... TEST=tast run dut12 audio.CrasEffects.\* # with CL:5033498 Cq-Depend: chromium:5033498 Change-Id: I9f807eaae9538f3e21bfae3a8f4fa059ea752c6f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5035238 Reviewed-by: Cheng-Yi Chiang Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com Commit-Queue: Li-Yu Yu --- cras/src/server/cras_iodev_list.c | 6 +++++- cras/src/tests/iodev_list_unittest.cc | 31 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cras/src/server/cras_iodev_list.c b/cras/src/server/cras_iodev_list.c index cc6a9d3f3..c5fa0b574 100644 --- a/cras/src/server/cras_iodev_list.c +++ b/cras/src/server/cras_iodev_list.c @@ -1342,7 +1342,11 @@ static bool can_use_dsp_aec(struct cras_rstream* all_streams) { if (effects & PRIVATE_DONT_CARE_APM_EFFECTS) { continue; } - if (!(effects & (APM_ECHO_CANCELLATION | DSP_ECHO_CANCELLATION_ALLOWED))) { + + // Block DSP AEC if any stream cannot use DSP AEC. + unsigned int dsp_aec_bits = + APM_ECHO_CANCELLATION | DSP_ECHO_CANCELLATION_ALLOWED; + if ((effects & dsp_aec_bits) != dsp_aec_bits) { return false; } } diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc index d0d651887..fd9277610 100644 --- a/cras/src/tests/iodev_list_unittest.cc +++ b/cras/src/tests/iodev_list_unittest.cc @@ -117,6 +117,7 @@ static int cras_stream_apm_add_called; static struct cras_floop_pair* cras_floop_pair_create_return; static bool cras_system_get_sr_bt_supported_return = false; static bool cras_system_get_noise_cancellation_enabled_ret = false; +static int cras_rstream_get_effects_return = 0; int dev_idx_in_vector(std::vector v, unsigned int idx) { return std::find(v.begin(), v.end(), idx) != v.end(); @@ -274,6 +275,7 @@ class IodevTests : public TestBase { cras_system_get_max_internal_mic_gain_return = DEFAULT_MAX_INPUT_NODE_GAIN; cras_floop_pair_create_return = NULL; cras_system_get_sr_bt_supported_return = false; + cras_rstream_get_effects_return = 0; } void SetUp() override { cras_iodev_list_reset(); @@ -3383,6 +3385,33 @@ TEST_F(IoDevTestSuite, BluetoothNbMicAudioEffectSrNotSupported) { cras_iodev_list_deinit(); } +TEST(CanUseDspAec, InputEffects) { + // next/prev are nullptr, single item list. + struct cras_rstream stream = { + .direction = CRAS_STREAM_INPUT, + }; + + cras_rstream_get_effects_return = 0; + EXPECT_EQ(can_use_dsp_aec(&stream), false); + + // DSP AEC needs both APM_ECHO_CANCELLATION and DSP_ECHO_CANCELLATION_ALLOWED + // bits. + cras_rstream_get_effects_return = APM_ECHO_CANCELLATION; + EXPECT_EQ(can_use_dsp_aec(&stream), false); + cras_rstream_get_effects_return = DSP_ECHO_CANCELLATION_ALLOWED; + EXPECT_EQ(can_use_dsp_aec(&stream), false); + + cras_rstream_get_effects_return = + APM_ECHO_CANCELLATION | DSP_ECHO_CANCELLATION_ALLOWED; + EXPECT_EQ(can_use_dsp_aec(&stream), true); + + cras_rstream_get_effects_return = PRIVATE_DONT_CARE_APM_EFFECTS; + EXPECT_EQ(can_use_dsp_aec(&stream), true); + + // Reset state. + cras_rstream_get_effects_return = 0; +} + } // namespace extern "C" { @@ -3664,7 +3693,7 @@ int cras_rstream_create(struct cras_rstream_config* config, void cras_rstream_destroy(struct cras_rstream* rstream) {} unsigned int cras_rstream_get_effects(const struct cras_rstream* stream) { - return 0; + return cras_rstream_get_effects_return; } struct cras_tm* cras_system_state_get_tm() {