From 31b31a6f97ee3a898c7baeabbf2239b853ccbfac Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 28 Mar 2022 15:04:52 +0200 Subject: [PATCH] stream: Only request more data when needed When we are not working RT, only request a buffer when we recycled one or when we had no buffers in the queue. The reason is that we only want to request a new buffer when the converter recycled a buffer and thus when the resampler has a new input size suggestion. We also want to request a new buffer when there is no new buffer to queue. This would be an underrun but we need to keep on requesting buffers in this case or else we stall forever. --- src/pipewire/stream.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index a90e01087..5184f5a29 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -987,16 +987,19 @@ static int impl_node_process_output(void *object) struct buffer *b; int res; uint32_t index; + bool recycled; again: pw_log_trace("%p: process out status:%d id:%d", stream, io->status, io->buffer_id); + recycled = false; if ((res = io->status) != SPA_STATUS_HAVE_DATA) { /* recycle old buffer */ if ((b = get_buffer(stream, io->buffer_id)) != NULL) { pw_log_trace("%p: recycle buffer %d", stream, b->id); push_queue(impl, &impl->dequeued, b); + recycled = true; } /* pop new buffer */ @@ -1023,12 +1026,12 @@ again: if (!impl->draining && !impl->driving) { /* we're not draining, not a driver check if we need to get * more buffers */ - if (!impl->process_rt) { + if (!impl->process_rt && (recycled || res == SPA_STATUS_NEED_DATA)) { /* not realtime and we have a free buffer, trigger process so that we have * data in the next round. */ if (spa_ringbuffer_get_read_index(&impl->dequeued.ring, &index) > 0) call_process(impl); - } else if (io->status == SPA_STATUS_NEED_DATA) { + } else if (res == SPA_STATUS_NEED_DATA) { /* realtime and we don't have a buffer, trigger process and try * again when there is something in the queue now */ call_process(impl);