Skip to content

Commit 1396d82

Browse files
afq984Chromeos LUCI
authored and
Chromeos LUCI
committed
Move feature_tier into s2
s2 will be used to instruct the DLC to download. BUG=b:356757315 TEST=bazel test //... Change-Id: I7a4b82fbd1d8b989cd6887fb73292489a309c776 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/6040757 Reviewed-by: Cranel W <[email protected]> Commit-Queue: Li-Yu Yu <[email protected]> Tested-by: Li-Yu Yu <[email protected]> Reviewed-by: Hung-Hsien Chen <[email protected]>
1 parent 4c9cd42 commit 1396d82

19 files changed

+96
-229
lines changed

Cargo.Bazel.lock

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "007a6f993637dd2a9588e36625c054d01a11ddca0e94f8fb0410c7b32cc02e32",
2+
"checksum": "9a241194a05459dda7f4c65786ed4ee920464ebcd778b6388ef33fdb661c390a",
33
"crates": {
44
"addr2line 0.20.0": {
55
"name": "addr2line",
@@ -2174,6 +2174,10 @@
21742174
{
21752175
"id": "log 0.4.20",
21762176
"target": "log"
2177+
},
2178+
{
2179+
"id": "serde 1.0.152",
2180+
"target": "serde"
21772181
}
21782182
],
21792183
"selects": {}

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/write_source_files/write_source_file_targets_generated.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
WRITE_SOURCE_FILE_TARGETS = [
88
"@//cras/common:generate_rust_common_h",
9-
"@//cras/server/feature_tier:generate_feature_tier_h",
109
"@//cras/server/ini:generate_ini_h",
1110
"@//cras/server/platform/dlc:generate_dlc_h",
1211
"@//cras/server/processor:generate_processor_h",

cras/server/feature_tier/BUILD.bazel

-17
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# found in the LICENSE file.
44

55
load("@crate_index//:defs.bzl", "all_crate_deps")
6-
load("@rules_cc//cc:defs.bzl", "cc_library")
76
load("@rules_rust//rust:defs.bzl", "rust_test")
87
load("//:utils.bzl", "require_no_config")
9-
load("//rules/cbindgen:rules.bzl", "cras_cbindgen")
108
load("//rules/rust:defs.bzl", "cras_rust_library")
119

1210
cras_rust_library(
@@ -25,18 +23,3 @@ rust_test(
2523
crate = ":feature_tier",
2624
target_compatible_with = require_no_config("//:system_cras_rust_build"),
2725
)
28-
29-
cras_cbindgen(
30-
name = "feature_tier_h",
31-
out = "feature_tier.h",
32-
copyright_year = 2024,
33-
extra_args = [],
34-
lib = ":feature_tier",
35-
)
36-
37-
cc_library(
38-
name = "cc",
39-
hdrs = ["feature_tier.h"],
40-
visibility = ["//visibility:public"],
41-
deps = [":feature_tier"],
42-
)

cras/server/feature_tier/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
[dependencies]
77
libc = { workspace = true }
88
log = { workspace = true }
9+
serde = { workspace = true }

cras/server/feature_tier/feature_tier.h

-47
This file was deleted.

cras/server/feature_tier/src/lib.rs

+44-63
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
use std::ffi::CStr;
6+
7+
use serde::Serialize;
8+
59
/// Support status for CRAS features.
6-
#[repr(C)]
10+
#[derive(Default, Serialize)]
711
pub struct CrasFeatureTier {
812
pub initialized: bool,
913
pub is_x86_64_v2: bool,
@@ -28,6 +32,42 @@ impl CrasFeatureTier {
2832
is_x86_64_v2: x86_64_v2,
2933
}
3034
}
35+
36+
/// Construct a CrasFeatureTier from NULL terminated strings.
37+
///
38+
/// # Safety
39+
///
40+
/// board_name and cpu_name must be a NULL terminated strings or NULLs.
41+
pub unsafe fn new_c(board_name: *const libc::c_char, cpu_name: *const libc::c_char) -> Self {
42+
let board_name = if board_name.is_null() {
43+
""
44+
} else {
45+
match CStr::from_ptr(board_name).to_str() {
46+
Ok(name) => name,
47+
Err(_) => "",
48+
}
49+
};
50+
51+
let cpu_name = if cpu_name.is_null() {
52+
""
53+
} else {
54+
match CStr::from_ptr(cpu_name).to_str() {
55+
Ok(name) => name,
56+
Err(_) => "",
57+
}
58+
};
59+
60+
let tier = CrasFeatureTier::new(board_name, cpu_name);
61+
62+
log::info!(
63+
"cras_feature_tier initialized with board={:?} cpu={:?} x86_64_v2={:?}",
64+
board_name,
65+
cpu_name,
66+
tier.is_x86_64_v2
67+
);
68+
69+
tier
70+
}
3171
}
3272

3373
#[cfg(any(target_arch = "x86_64"))]
@@ -93,68 +133,9 @@ mod tests {
93133
assert!(has_substr("DisalLoWed", &["abc", "Dis"]));
94134
assert!(!has_substr("DisalLoWed", &["abc"]));
95135
}
96-
}
97-
98-
pub mod bindings {
99-
use std::ffi::CStr;
100-
101-
pub use super::CrasFeatureTier;
102-
103-
#[no_mangle]
104-
/// Initialize the cras feature tier struct.
105-
/// On error, a negative error code is returned.
106-
///
107-
/// # Safety
108-
///
109-
/// out must be non-NULL.
110-
pub unsafe extern "C" fn cras_feature_tier_init(
111-
out: *mut CrasFeatureTier,
112-
board_name: *const libc::c_char,
113-
cpu_name: *const libc::c_char,
114-
) -> libc::c_int {
115-
let board_name = if board_name.is_null() {
116-
""
117-
} else {
118-
match CStr::from_ptr(board_name).to_str() {
119-
Ok(name) => name,
120-
Err(_) => return -libc::EINVAL,
121-
}
122-
};
123-
124-
let cpu_name = if cpu_name.is_null() {
125-
""
126-
} else {
127-
match CStr::from_ptr(cpu_name).to_str() {
128-
Ok(name) => name,
129-
Err(_) => return -libc::EINVAL,
130-
}
131-
};
132-
133-
let tier = CrasFeatureTier::new(board_name, cpu_name);
134-
135-
log::info!(
136-
"cras_feature_tier initialized with board={:?} cpu={:?} x86_64_v2={:?}",
137-
board_name,
138-
cpu_name,
139-
tier.is_x86_64_v2
140-
);
141-
142-
*out = tier;
143-
144-
0
145-
}
146136

147-
#[cfg(test)]
148-
mod tests {
149-
use super::*;
150-
151-
#[test]
152-
fn null_safety() {
153-
let mut tier = std::mem::MaybeUninit::<CrasFeatureTier>::zeroed();
154-
let rc = unsafe {
155-
cras_feature_tier_init(tier.as_mut_ptr(), std::ptr::null(), std::ptr::null())
156-
};
157-
assert_eq!(0, rc);
158-
}
137+
#[test]
138+
fn null_safety() {
139+
unsafe { CrasFeatureTier::new_c(std::ptr::null(), std::ptr::null()) };
159140
}
160141
}

cras/server/s2/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ cras_rust_library(
2020
deps = all_crate_deps(normal = True) + [
2121
"//audio_processor",
2222
"//cras/common:rust_common",
23+
"//cras/server/feature_tier",
2324
"//cras/server/ini",
2425
],
2526
)

cras/server/s2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2021"
99
audio_processor = { workspace = true }
1010
cras_common = { workspace = true }
1111
cras_ini = { workspace = true }
12+
cras_feature_tier = { workspace = true }
1213

1314
anyhow = { workspace = true }
1415
libc = { workspace = true }

cras/server/s2/s2.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ void cras_s2_set_ap_nc_featured_allowed(bool allowed);
2727

2828
void cras_s2_set_ap_nc_segmentation_allowed(bool allowed);
2929

30-
void cras_s2_set_ap_nc_feature_tier_allowed(bool allowed);
31-
3230
bool cras_s2_are_audio_effects_ready(void);
3331

3432
void cras_s2_set_notify_audio_effect_ui_appearance_changed(NotifyAudioEffectUIAppearanceChanged notify_audio_effect_ui_appearance_changed);
@@ -53,7 +51,12 @@ void cras_s2_set_voice_isolation_ui_enabled(bool enabled);
5351

5452
bool cras_s2_get_voice_isolation_ui_enabled(void);
5553

56-
void cras_s2_init(void);
54+
/**
55+
* # Safety
56+
*
57+
* board_name and cpu_name must be NULL-terminated strings or NULLs.
58+
*/
59+
void cras_s2_init(const char *board_name, const char *cpu_name);
5760

5861
bool cras_s2_get_beamforming_supported(void);
5962

@@ -103,6 +106,8 @@ void cras_s2_set_spatial_audio_supported(bool supported);
103106

104107
bool cras_s2_get_spatial_audio_supported(void);
105108

109+
bool cras_s2_get_sr_bt_supported(void);
110+
106111
#endif /* CRAS_SERVER_S2_S2_H_ */
107112

108113
#ifdef __cplusplus

cras/server/s2/src/global.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use cras_common::types_internal::CrasEffectUIAppearance;
1616
use cras_common::types_internal::CrasProcessorEffect;
1717
use cras_common::types_internal::CRAS_NC_PROVIDER;
1818
use cras_common::types_internal::EFFECT_TYPE;
19+
use cras_feature_tier::CrasFeatureTier;
1920

2021
use crate::processing::BeamformingConfig;
2122

@@ -36,11 +37,6 @@ pub extern "C" fn cras_s2_set_ap_nc_segmentation_allowed(allowed: bool) {
3637
state().set_ap_nc_segmentation_allowed(allowed);
3738
}
3839

39-
#[no_mangle]
40-
pub extern "C" fn cras_s2_set_ap_nc_feature_tier_allowed(allowed: bool) {
41-
state().set_ap_nc_feature_tier_allowed(allowed);
42-
}
43-
4440
pub fn set_dlc_manager_ready() {
4541
state().set_dlc_manager_ready();
4642
}
@@ -132,17 +128,25 @@ pub extern "C" fn cras_s2_get_voice_isolation_ui_enabled() -> bool {
132128
state().input.voice_isolation_ui_enabled
133129
}
134130

131+
/// # Safety
132+
///
133+
/// board_name and cpu_name must be NULL-terminated strings or NULLs.
135134
#[no_mangle]
136-
pub extern "C" fn cras_s2_init() {
135+
pub unsafe extern "C" fn cras_s2_init(
136+
board_name: *const libc::c_char,
137+
cpu_name: *const libc::c_char,
138+
) {
139+
let mut s = state();
137140
match std::fs::read_to_string("/run/chromeos-config/v1/audio/main/cras-config-dir") {
138141
Ok(str) => {
139-
state().read_cras_config(&str);
142+
s.read_cras_config(&str);
140143
}
141144
Err(err) => {
142-
state().read_cras_config("");
145+
s.read_cras_config("");
143146
log::error!("Failed to read cras-config-dir: {err:#}");
144147
}
145148
}
149+
s.set_feature_tier(CrasFeatureTier::new_c(board_name, cpu_name));
146150
}
147151

148152
#[no_mangle]
@@ -294,3 +298,8 @@ pub fn cras_s2_get_beamforming_config_path() -> Option<PathBuf> {
294298
BeamformingConfig::Unsupported { .. } => None,
295299
}
296300
}
301+
302+
#[no_mangle]
303+
pub extern "C" fn cras_s2_get_sr_bt_supported() -> bool {
304+
state().input.feature_tier.sr_bt_supported
305+
}

0 commit comments

Comments
 (0)