summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-07-29 09:49:06 +0200
committerWim Taymans <wtaymans@redhat.com>2020-07-29 09:49:06 +0200
commit55bef12cda37490ad3555ca0dc724697241c33f1 (patch)
tree658fd5fa1201bd6432aabdf3cd859d9682e96ed0
parentc04d57d5d5500fa7c7b40c02f8b586967f3db47b (diff)
pulse: take queued data into account when asking for more
Don't use always ask for the maximum amount of data in the write_callback but subtract the queued amount of data from it or else we will queue too much and cause huge lag. Fixes #258
-rw-r--r--pipewire-pulseaudio/src/stream.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/pipewire-pulseaudio/src/stream.c b/pipewire-pulseaudio/src/stream.c
index 1ac0d2b8..7b529a95 100644
--- a/pipewire-pulseaudio/src/stream.c
+++ b/pipewire-pulseaudio/src/stream.c
@@ -552,10 +552,16 @@ static void stream_process(void *data)
update_timing_info(s);
if (s->direction == PA_STREAM_PLAYBACK) {
+ pa_timing_info *i = &s->timing_info;
+ uint64_t queued, writable;
+
queue_output(s);
- if (s->write_callback && s->state == PA_STREAM_READY)
- s->write_callback(s, s->maxblock, s->write_userdata);
+ queued = i->write_index - SPA_MIN(i->read_index, i->write_index);
+ writable = s->maxblock - SPA_MIN(queued, s->maxblock);
+
+ if (s->write_callback && s->state == PA_STREAM_READY && writable > 0)
+ s->write_callback(s, writable, s->write_userdata);
}
else {
pull_input(s);
@@ -1843,6 +1849,9 @@ int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative)
else
*r_usec = time_counter_diff(s, t, c, negative);
+ pw_log_debug("stream %p: now:%"PRIu64" stream:%"PRIu64
+ " res:%"PRIu64, s, t, c, *r_usec);
+
return 0;
}