]> git.nihav.org Git - nihav-player.git/commitdiff
sndplay: do not hang in the audio callback function master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 27 Nov 2026 11:33:45 +0000 (12:33 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 27 Nov 2026 11:33:45 +0000 (12:33 +0100)
sndplay/src/main.rs

index 914233a04b56dae0bec4469177a721934d1472fc..a42f41d7914c93c4eae6c7abbb2f8649361c42dc 100644 (file)
@@ -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}"); };