mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-22 16:25:06 +03:00
Add suspend handling
ALSA needs special handling to correctly resume after the system is suspended with a PCM active. Do the required dance. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
cfde41c18e
commit
157ddc4e41
1 changed files with 16 additions and 1 deletions
17
src/main.rs
17
src/main.rs
|
@ -17,6 +17,7 @@ use configparser::ini::Ini;
|
||||||
use log;
|
use log;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use simple_logger::SimpleLogger;
|
use simple_logger::SimpleLogger;
|
||||||
|
use alsa::nix::errno::Errno;
|
||||||
|
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod types;
|
mod types;
|
||||||
|
@ -200,7 +201,21 @@ fn main() {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Block while we're reading into the buffer
|
// Block while we're reading into the buffer
|
||||||
io.readi(&mut buf).unwrap();
|
io.readi(&mut buf).or_else(|e| {
|
||||||
|
if e.errno() == Errno::ESTRPIPE {
|
||||||
|
// Resume handling
|
||||||
|
loop {
|
||||||
|
match pcm.resume() {
|
||||||
|
Ok(_) => break Ok(0),
|
||||||
|
Err(e) if e.errno() == Errno::EAGAIN => continue,
|
||||||
|
Err(e) => break Err(e),
|
||||||
|
}
|
||||||
|
}.unwrap();
|
||||||
|
io.readi(&mut buf)
|
||||||
|
} else {
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
let cur_sample_rate = sample_rate_elem.read_int(&ctl);
|
let cur_sample_rate = sample_rate_elem.read_int(&ctl);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue