From: Kostya Shishkov Date: Fri, 27 Nov 2026 11:33:45 +0000 (+0100) Subject: sndplay: do not hang in the audio callback function X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=d56c800308115d0b59b82b3ed27ce336db480aea;p=nihav-player.git sndplay: do not hang in the audio callback function --- diff --git a/sndplay/src/main.rs b/sndplay/src/main.rs index 914233a..a42f41d 100644 --- a/sndplay/src/main.rs +++ b/sndplay/src/main.rs @@ -101,11 +101,19 @@ impl AudioDevice { let queue = Arc::clone(&self.queue); let data_cb = move |dst: &mut [i16], _: &cpal::OutputCallbackInfo| { let mut pos = 0; - while pos < dst.len() { + let mut niters = 0; + while pos < dst.len() && niters < 1_000_000 { if let Ok(mut queue) = queue.try_lock() { let copy_len = queue.drain(&mut dst[pos..]); pos += copy_len; } + niters += 1; + } + if pos < dst.len() { + println!("underrun!"); + for el in dst[pos..].iter_mut() { + *el = 0; + } } }; let error_cb = |err| { println!(" audio error {err}"); };