mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-22 08:15:07 +03:00
main: Work around visense kernel channel swap bug
This is ugly and we really should figure out why the kernel admac stuff borks, but it'll do for now... Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
4bbda81f68
commit
ea4a8e9d35
1 changed files with 24 additions and 11 deletions
31
src/main.rs
31
src/main.rs
|
@ -210,9 +210,9 @@ fn main() {
|
||||||
|
|
||||||
let pcm_name = format!("{},{}", device, globals.visense_pcm);
|
let pcm_name = format!("{},{}", device, globals.visense_pcm);
|
||||||
// Set up PCM to buffer in V/ISENSE
|
// Set up PCM to buffer in V/ISENSE
|
||||||
let pcm: alsa::pcm::PCM =
|
let mut pcm: Option<alsa::pcm::PCM> =
|
||||||
helpers::open_pcm(&pcm_name, globals.channels.try_into().unwrap(), 0);
|
Some(helpers::open_pcm(&pcm_name, globals.channels.try_into().unwrap(), 0));
|
||||||
let io = pcm.io_i16().unwrap();
|
let mut io = Some(pcm.as_ref().unwrap().io_i16().unwrap());
|
||||||
|
|
||||||
let mut sample_rate_elem = types::Elem::new(
|
let mut sample_rate_elem = types::Elem::new(
|
||||||
"Speaker Sample Rate".to_string(),
|
"Speaker Sample Rate".to_string(),
|
||||||
|
@ -253,14 +253,19 @@ fn main() {
|
||||||
panic!("SIGQUIT received");
|
panic!("SIGQUIT received");
|
||||||
}
|
}
|
||||||
// Block while we're reading into the buffer
|
// Block while we're reading into the buffer
|
||||||
let read = io
|
let read = io.as_ref().unwrap().readi(&mut buf);
|
||||||
.readi(&mut buf)
|
|
||||||
.or_else(|e| {
|
#[allow(unused_mut)]
|
||||||
|
#[allow(unused_assignments)]
|
||||||
|
let read = match read {
|
||||||
|
Ok(a) => Ok(a),
|
||||||
|
Err(e) => {
|
||||||
if sigquit.load(Ordering::Relaxed) {
|
if sigquit.load(Ordering::Relaxed) {
|
||||||
panic!("SIGQUIT received");
|
panic!("SIGQUIT received");
|
||||||
}
|
}
|
||||||
if e.errno() == Errno::ESTRPIPE {
|
if e.errno() == Errno::ESTRPIPE {
|
||||||
warn!("Suspend detected!");
|
warn!("Suspend detected!");
|
||||||
|
/*
|
||||||
// Resume handling
|
// Resume handling
|
||||||
loop {
|
loop {
|
||||||
match pcm.resume() {
|
match pcm.resume() {
|
||||||
|
@ -271,12 +276,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
warn!("Resume successful");
|
warn!("Resume successful");
|
||||||
io.readi(&mut buf)
|
*/
|
||||||
} else {
|
// Work around kernel issue: resume sometimes breaks visense
|
||||||
|
warn!("Reinitializing PCM to work around kernel bug...");
|
||||||
|
io = None;
|
||||||
|
pcm = None;
|
||||||
|
pcm = Some(helpers::open_pcm(&pcm_name, globals.channels.try_into().unwrap(), 0));
|
||||||
|
io = Some(pcm.as_ref().unwrap().io_i16().unwrap());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Err(e)
|
Err(e)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if read != globals.period {
|
if read != globals.period {
|
||||||
warn!("Expected {} samples, got {}", globals.period, read);
|
warn!("Expected {} samples, got {}", globals.period, read);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue