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/polyplib-stream.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'polyp/polyplib-stream.c') diff --git a/polyp/polyplib-stream.c b/polyp/polyplib-stream.c index c8fef673..286702b2 100644 --- a/polyp/polyplib-stream.c +++ b/polyp/polyplib-stream.c @@ -687,6 +687,24 @@ pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info * return usec; } +static pa_usec_t time_counter_diff(struct pa_stream *s, pa_usec_t t, pa_usec_t c, int *negative) { + assert(s); + + if (negative) + *negative = 0; + + if (c < t) { + if (s->direction == PA_STREAM_RECORD) { + if (negative) + *negative = 1; + + return t-c; + } else + return 0; + } else + return c-t; +} + pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative) { pa_usec_t t, c; assert(s && i); @@ -694,18 +712,7 @@ pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_inf t = pa_stream_get_time(s, i); c = pa_bytes_to_usec(s->counter, &s->sample_spec); - if (t <= c) { - if (negative) - *negative = 1; - - return c-t; - } else { - if (negative) - *negative = 0; - return t-c; - } - - return 0; + return time_counter_diff(s, t, c, negative); } const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s) { @@ -749,15 +756,6 @@ pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative) t = pa_stream_get_interpolated_time(s); c = pa_bytes_to_usec(s->counter, &s->sample_spec); - - if (t <= c) { - if (negative) - *negative = 1; - - return c-t; - } else { - if (negative) - *negative = 0; - return t-c; - } + + return time_counter_diff(s, t, c, negative); } -- cgit