changeset 3184:b009fad90e92

alsa-ng: buffer timing cleanups
author Joris van Rantwijk <joris2822@xs4all.nl>
date Sun, 14 Jun 2009 23:10:04 -0500
parents 19e3ec80dac9
children d3cf6d14c960
files src/alsa-ng/alsa-core.c
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/alsa-ng/alsa-core.c	Fri Jun 12 17:15:10 2009 -0400
+++ b/src/alsa-ng/alsa-core.c	Sun Jun 14 23:10:04 2009 -0500
@@ -315,7 +315,10 @@
     bitwidth = snd_pcm_format_physical_width(afmt);
     bps = (rate * bitwidth * nch) >> 3;
     ringbuf_size = aud_cfg->output_buffer_size * bps / 1000;
-    alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size);
+    if (alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size) == -1) {
+        _ERROR("alsaplug_ringbuffer_init failed");
+        return -1;
+    }
     pcm_going = TRUE;
     flush_request = -1;
 
@@ -371,14 +374,15 @@
 
     if (pcm_going && pcm_handle != NULL)
     {
+        guint d = alsaplug_ringbuffer_used(&pcm_ringbuf);
+
         if (!snd_pcm_delay(pcm_handle, &delay))
-        {
-            guint d = snd_pcm_frames_to_bytes(pcm_handle, delay);
-            if (bytes < d)
-                bytes = 0;
-            else
-                bytes -= d;
-        }
+            d += snd_pcm_frames_to_bytes(pcm_handle, delay);
+
+        if (bytes < d)
+            bytes = 0;
+        else
+            bytes -= d;
 
         ret = bytes * (long long) 1000 / bps;
     }