From e53eefef0df1e438db29a27049c5f08c84675263 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 8 Jul 2022 10:48:29 +0200 Subject: [PATCH] stream: implement prefetch When the audioconverter needs more data, let it return NEED_DATA. This can happen before the ports actually have consumed all the input data. For example, then the next cycle would require 1024 samples but there are currently only 16 samples queued, the next cycle will consume the 16 samples and then need another buffer to produce output. For rt streams, this is not a problem because a new buffer will be fetched in the next cycle synchronously. When the stream is async, we can use this NEED_DATA to prefetch a new buffer so that we have one in the next cycle. This fixes hickups with async streams that provide random sized buffers. --- spa/plugins/audioconvert/audioconvert.c | 5 +++-- src/pipewire/stream.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 9e044dba5..7c62cdee2 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -2642,9 +2642,10 @@ static int impl_node_process(void *object) spa_log_trace_fp(this->log, "%p: no output buffer", this); } } - resample_update_rate_match(this, resample_passthrough, + if (resample_update_rate_match(this, resample_passthrough, max_out - this->out_offset, - max_in - this->in_offset); + max_in - this->in_offset) > 0) + res |= SPA_STATUS_NEED_DATA; return res; } diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index f35de287e..3d5443a4f 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1061,6 +1061,10 @@ again: pw_log_trace_fp("%p: no more buffers %p", stream, io); ask_more = true; } + } else { + ask_more = !impl->process_rt && + queue_is_empty(impl, &impl->queued) && + !queue_is_empty(impl, &impl->dequeued); } copy_position(impl, impl->queued.outcount);