From 02a4fcfe83e7810a9eb045893d8d53875077b32c Mon Sep 17 00:00:00 2001 From: Li-Yu Yu Date: Fri, 27 Dec 2024 11:25:09 +0800 Subject: [PATCH] s2: Disallow BF/AST when voice_isolation_ui_preferred_effect is NC FIXED=b:383772089 TEST=tast run dut1 audio.CrasNoiseCancellation.\* Change-Id: I652482d422c3ec212f2f0f96e557b22c524cf997 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/6109885 Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com Commit-Queue: Hung-Hsien Chen Reviewed-by: Hung-Hsien Chen --- cras/common/src/types_internal.rs | 17 +++++++++++++++++ cras/server/s2/src/lib.rs | 13 ++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cras/common/src/types_internal.rs b/cras/common/src/types_internal.rs index 86023fde..2a667bf0 100644 --- a/cras/common/src/types_internal.rs +++ b/cras/common/src/types_internal.rs @@ -134,6 +134,23 @@ impl EFFECT_TYPE { _ => c"Invalid NC provider", } } + + /// Return the set of NC providers for this effect type. + pub fn nc_providers(&self) -> CRAS_NC_PROVIDER { + match self { + &EFFECT_TYPE::NOISE_CANCELLATION => CRAS_NC_PROVIDER::AP | CRAS_NC_PROVIDER::DSP, + &EFFECT_TYPE::STYLE_TRANSFER => { + CRAS_NC_PROVIDER::AP | CRAS_NC_PROVIDER::DSP | CRAS_NC_PROVIDER::AST + } + &EFFECT_TYPE::BEAMFORMING => { + CRAS_NC_PROVIDER::AP + | CRAS_NC_PROVIDER::DSP + | CRAS_NC_PROVIDER::AST + | CRAS_NC_PROVIDER::BF + } + _ => CRAS_NC_PROVIDER::all(), + } + } } /// Returns the name of the effect type as a string. diff --git a/cras/server/s2/src/lib.rs b/cras/server/s2/src/lib.rs index 702b44a0..c3efbf82 100644 --- a/cras/server/s2/src/lib.rs +++ b/cras/server/s2/src/lib.rs @@ -190,7 +190,7 @@ fn resolve(input: &Input) -> Output { }, }; - let mut system_valid_nc_providers = audio_effects_status + let system_valid_nc_providers = audio_effects_status .iter() .filter_map(|(provider, status)| { if status.supported_and_allowed() { @@ -199,10 +199,8 @@ fn resolve(input: &Input) -> Output { None } }) - .fold(CRAS_NC_PROVIDER::empty(), CRAS_NC_PROVIDER::union); - if input.voice_isolation_ui_preferred_effect == EFFECT_TYPE::STYLE_TRANSFER { - system_valid_nc_providers.remove(CRAS_NC_PROVIDER::BF); - } + .fold(CRAS_NC_PROVIDER::empty(), CRAS_NC_PROVIDER::union) + & input.voice_isolation_ui_preferred_effect.nc_providers(); Output { audio_effects_ready: input @@ -942,6 +940,11 @@ mod tests { | CRAS_NC_PROVIDER::AST | CRAS_NC_PROVIDER::BF ); + s.set_voice_isolation_ui_preferred_effect(EFFECT_TYPE::NOISE_CANCELLATION); + assert_eq!( + s.output.system_valid_nc_providers, + CRAS_NC_PROVIDER::AP | CRAS_NC_PROVIDER::DSP + ); } #[test]