Skip to content

Commit

Permalink
CRAS: add spatial audio state in s2
Browse files Browse the repository at this point in the history
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 <eddyhsu@chromium.org>
Reviewed-by: Li-Yu Yu <aaronyu@google.com>
Reviewed-by: Hung-Hsien Chen <hunghsienchen@chromium.org>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
  • Loading branch information
Eddy Hsu authored and Chromeos LUCI committed Oct 4, 2024
1 parent 8648c35 commit cf4644a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cras/server/s2/s2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cras/server/s2/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
18 changes: 18 additions & 0 deletions cras/server/s2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit cf4644a

Please sign in to comment.