summaryrefslogtreecommitdiffstats
path: root/polyp/polyplib-stream.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-10-27 14:14:30 +0000
committerLennart Poettering <lennart@poettering.net>2004-10-27 14:14:30 +0000
commit49e16ffc6c87fd879e4143730fd211560ffee0a4 (patch)
treeea78e17741711080880d9a3482f0e39b31416d39 /polyp/polyplib-stream.c
parentee452b0f06c82dd870de82fb3e6bdd4e14d29f3c (diff)
latency calculation fix
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@258 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/polyplib-stream.c')
-rw-r--r--polyp/polyplib-stream.c44
1 files changed, 21 insertions, 23 deletions
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);
}