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@canonical.com --- pulse/pcm_pulse.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/pulse/pcm_pulse.c b/pulse/pcm_pulse.c index d6c6792..9c4a7e5 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;
@@ -459,6 +460,7 @@ static snd_pcm_sframes_t pulse_write(snd_pcm_ioplug_t * io, }
/* Make sure the buffer pointer is in sync */ + pcm->written += writebytes; pcm->last_size -= writebytes; ret = update_ptr(pcm); if (ret < 0) @@ -594,7 +596,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 +694,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 +987,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;