The tsched watermark variable was incorrectly used even for sinks
with timer scheduling disabled, causing XRUNs on every rewind. This
patch sets a fixed margin of 20 msec for such rewinds, thus avoiding
the underrun.

One could argue that the margin should be adjustable somehow (or based
on fragment-size, or something else), but this patch at least fixes the
immediate problem, causing "crackling" output on (at least) one machine.

-- 
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
>From 87e8a04f029c18cdb5abebb4f3f3c2100d42107a Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Tue, 17 Aug 2010 19:37:51 +0200
Subject: [PATCH] Do not use tsched watermark if tsched is disabled

The tsched watermark variable was incorrectly used even for sinks
with timer scheduling disabled, causing XRUNs on every rewind. This
patch sets a fixed margin of 20 msec for such rewinds, thus avoiding
the underrun.

Signed-off-by: David Henningsson <[email protected]>
---
 src/modules/alsa/alsa-sink.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index a253cc5..9202883 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -63,6 +63,8 @@
 
 #define DEFAULT_DEVICE "default"
 
+#define NON_TSCHED_REWIND_MARGIN_USEC (20*PA_USEC_PER_MSEC)        /* 20ms  -- Rewind margin for non-tsched devices */
+
 #define DEFAULT_TSCHED_BUFFER_USEC (2*PA_USEC_PER_SEC)             /* 2s    -- Overall buffer size */
 #define DEFAULT_TSCHED_WATERMARK_USEC (20*PA_USEC_PER_MSEC)        /* 20ms  -- Fill up when only this much is left in the buffer */
 
@@ -1309,7 +1311,11 @@ static int process_rewind(struct userdata *u) {
         return -1;
     }
 
-    unused_nbytes = u->tsched_watermark + (size_t) unused * u->frame_size;
+    unused_nbytes = (size_t) unused * u->frame_size;
+    if (u->use_tsched)
+        unused_nbytes += u->tsched_watermark;
+    else
+        unused_nbytes += pa_usec_to_bytes(NON_TSCHED_REWIND_MARGIN_USEC, &u->sink->sample_spec);
 
     if (u->hwbuf_size > unused_nbytes)
         limit_nbytes = u->hwbuf_size - unused_nbytes;
-- 
1.7.0.4

_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

Reply via email to