pub fn detect_hardware_sink() -> Option<String> {
let out = std::process::Command::new("pw-metadata")
.args(["-n", "default", "0", "default.audio.sink"])
.output()
.ok()?;
let s = String::from_utf8_lossy(&out.stdout);
let start = s.find("\"name\":\"")?;
let rest = &s[start + 8..];
let end = rest.find('"')?;
let name = &rest[..end];
if name == "NAM-rs-input" || name == "NAM-rs-standalone" {
None
} else {
Some(name.to_string())
}
}
pub fn lock_cpu_c_states() -> Option<std::fs::File> {
match std::fs::OpenOptions::new()
.write(true)
.open("/dev/cpu_dma_latency")
{
Ok(mut file) => {
let zero: i32 = 0;
if std::io::Write::write_all(&mut file, &zero.to_ne_bytes()).is_ok() {
log::info!("⚡ PM QoS Lock: Deep CPU C-States disabled (Zero DMA Latency).");
return Some(file);
}
log::warn!("PM QoS: Failed to write to /dev/cpu_dma_latency.");
None
}
Err(e) => {
log::warn!(
"PM QoS: Access denied to /dev/cpu_dma_latency ({}). \
Consider creating a udev rule for the 'audio' group.",
e
);
None
}
}
}