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
This commit is contained in:
Wim Taymans 2020-07-29 09:49:06 +02:00
parent c04d57d5d5
commit 55bef12cda

View file

@ -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;
}