Skip to content

Commit

Permalink
can_use_dsp_aec: Fix not checking both bits for DSP AEC
Browse files Browse the repository at this point in the history
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 <cychiang@chromium.org>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Commit-Queue: Li-Yu Yu <aaronyu@google.com>
  • Loading branch information
afq984 authored and Chromeos LUCI committed Nov 16, 2023
1 parent 6a9b917 commit 5cb8439
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cras/src/server/cras_iodev_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
31 changes: 30 additions & 1 deletion cras/src/tests/iodev_list_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int> v, unsigned int idx) {
return std::find(v.begin(), v.end(), idx) != v.end();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5cb8439

Please sign in to comment.