From 49e16ffc6c87fd879e4143730fd211560ffee0a4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 27 Oct 2004 14:14:30 +0000 Subject: latency calculation fix git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@258 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/sink-input.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'polyp/sink-input.c') diff --git a/polyp/sink-input.c b/polyp/sink-input.c index 5c8675de..dac10953 100644 --- a/polyp/sink-input.c +++ b/polyp/sink-input.c @@ -69,8 +69,10 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con i->kill = NULL; i->get_latency = NULL; i->userdata = NULL; + i->underrun = NULL; i->volume = PA_VOLUME_NORM; + i->playing = 0; i->resampled_chunk.memblock = NULL; i->resampled_chunk.index = i->resampled_chunk.length = 0; @@ -156,20 +158,19 @@ pa_usec_t pa_sink_input_get_latency(struct pa_sink_input *i) { } int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) { - int ret = 0; + int ret = -1; assert(i && chunk && i->ref >= 1); - if (!i->peek || !i->drop) - return -1; - - if (i->state == PA_SINK_INPUT_CORKED) - return -1; - - if (!i->resampler) - return i->peek(i, chunk); - pa_sink_input_ref(i); + if (!i->peek || !i->drop || i->state == PA_SINK_INPUT_CORKED) + goto finish; + + if (!i->resampler) { + ret = i->peek(i, chunk); + goto finish; + } + while (!i->resampled_chunk.memblock) { struct pa_memchunk tchunk; size_t l; @@ -199,6 +200,11 @@ int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) { finish: + if (ret < 0 && i->playing && i->underrun) + i->underrun(i); + + i->playing = ret >= 0; + pa_sink_input_unref(i); return ret; -- cgit