[PATCH] alsa-plugins: Pulse: only underrun if no more data has been written
David Henningsson
david.henningsson at canonical.com
Tue Aug 2 05:49:04 PDT 2011
If more data has already been written after the underrun, the underrun
will automatically end and therefore we should not report it or
restart the stream.
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
pulse/pcm_pulse.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/pulse/pcm_pulse.c b/pulse/pcm_pulse.c
index d6c6792..e43504e 100644
--- a/pulse/pcm_pulse.c
+++ b/pulse/pcm_pulse.c
@@ -39,9 +39,10 @@ typedef struct snd_pcm_pulse {
size_t last_size;
size_t ptr;
int underrun;
- int handle_underrun;
+ int handle_underrun; /* can be 0=never, 1=always or 2=only if more data has not been written */
size_t offset;
+ int64_t written;
pa_stream *stream;
@@ -594,7 +595,8 @@ static void stream_underrun_cb(pa_stream * p, void *userdata)
if (!pcm->p)
return;
- pcm->underrun = 1;
+ if (pcm->handle_underrun == 1 || pcm->written <= pa_stream_get_underflow_index(p))
+ pcm->underrun = 1;
}
static void stream_latency_cb(pa_stream *p, void *userdata) {
@@ -691,6 +693,7 @@ static int pulse_prepare(snd_pcm_ioplug_t * io)
goto finish;
}
+ pcm->written = 0;
pa_stream_set_state_callback(pcm->stream, stream_state_cb, pcm);
pa_stream_set_latency_update_callback(pcm->stream, stream_latency_cb, pcm);
@@ -983,7 +986,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(pulse)
const char *server = NULL;
const char *device = NULL;
const char *fallback_name = NULL;
- int handle_underrun = 0;
+ int handle_underrun = 2;
int err;
snd_pcm_pulse_t *pcm;
--
1.7.4.1
--------------070703080500020509090608--
More information about the pulseaudio-discuss
mailing list