From cf4644a08f98ab27089b74a6b10beaff1b770f29 Mon Sep 17 00:00:00 2001 From: Eddy Hsu Date: Thu, 26 Sep 2024 18:32:31 +0000 Subject: [PATCH] CRAS: add spatial audio state in s2 Add spatial audio in system state s2. BUG=b:317748801 TEST=FEATURES=test USE=asan emerge-${BOARD} adhd, bazel test //... Change-Id: Ia0ce20d97a85a788c0f2503cd2eac4c550f05928 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5893960 Commit-Queue: Eddy Hsu Reviewed-by: Li-Yu Yu Reviewed-by: Hung-Hsien Chen Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com --- cras/server/s2/s2.h | 4 ++++ cras/server/s2/src/global.rs | 10 ++++++++++ cras/server/s2/src/lib.rs | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/cras/server/s2/s2.h b/cras/server/s2/s2.h index b58b47cb9..cc2485da7 100644 --- a/cras/server/s2/s2.h +++ b/cras/server/s2/s2.h @@ -69,6 +69,10 @@ bool cras_s2_get_bypass_block_dsp_nc(void); void cras_s2_set_active_input_node_compatible_nc_providers(CRAS_NC_PROVIDER compatible_nc_providers); +void cras_s2_set_spatial_audio_enabled(bool enabled); + +bool cras_s2_get_spatial_audio_enabled(void); + #endif /* CRAS_SERVER_S2_S2_H_ */ #ifdef __cplusplus diff --git a/cras/server/s2/src/global.rs b/cras/server/s2/src/global.rs index 8f0e4b86d..3565ded4f 100644 --- a/cras/server/s2/src/global.rs +++ b/cras/server/s2/src/global.rs @@ -166,3 +166,13 @@ pub extern "C" fn cras_s2_set_active_input_node_compatible_nc_providers( ) { state().set_active_input_node_compatible_nc_providers(compatible_nc_providers); } + +#[no_mangle] +pub extern "C" fn cras_s2_set_spatial_audio_enabled(enabled: bool) { + state().set_spatial_audio_enabled(enabled); +} + +#[no_mangle] +pub extern "C" fn cras_s2_get_spatial_audio_enabled() -> bool { + state().input.spatial_audio_enabled +} diff --git a/cras/server/s2/src/lib.rs b/cras/server/s2/src/lib.rs index 73b3e2f9c..f14297ee6 100644 --- a/cras/server/s2/src/lib.rs +++ b/cras/server/s2/src/lib.rs @@ -69,6 +69,7 @@ struct Input { // integrated without AEC on DSP. 0 - otherwise. nc_standalone_mode: bool, bypass_block_dsp_nc: bool, + spatial_audio_enabled: bool, } #[derive(Serialize)] @@ -345,6 +346,11 @@ impl S2 { Ok(()) } + fn set_spatial_audio_enabled(&mut self, enabled: bool) { + self.input.spatial_audio_enabled = enabled; + self.update(); + } + fn update(&mut self) { self.output = resolve(&self.input); } @@ -628,4 +634,16 @@ mod tests { expected.remove(CRAS_NC_PROVIDER::AST); assert_eq!(s.output.system_valid_nc_providers, expected); } + + #[test] + fn test_spatial_audio_enabled() { + let mut s = S2::new(); + assert_eq!(s.input.spatial_audio_enabled, false); + + s.set_spatial_audio_enabled(true); + assert_eq!(s.input.spatial_audio_enabled, true); + + s.set_spatial_audio_enabled(false); + assert_eq!(s.input.spatial_audio_enabled, false); + } }