From 1a12d6082a4e325c3b846308c04453d385ae6f78 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 25 Feb 2021 12:05:28 +0100 Subject: [PATCH] stream: improve draining After we drained, set the io state to NEED_DATA again. This will trigger a new _process callback, if we have new buffers we will exit the drain state and produce more data, if we have no buffers we reenter the drained state and signal the drained event. This effectively provides a way to exit the drain state by pushing a new buffer into the stream. --- src/pipewire/stream.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index d4d70a26a..9e9952c1e 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -833,10 +833,12 @@ again: /* pop new buffer */ if ((b = pop_queue(impl, &impl->queued)) != NULL) { + impl->drained = false; io->buffer_id = b->id; res = io->status = SPA_STATUS_HAVE_DATA; pw_log_trace(NAME" %p: pop %d %p", stream, b->id, io); - } else if (impl->draining) { + } else if (impl->draining || impl->drained) { + impl->draining = true; impl->drained = true; io->buffer_id = SPA_ID_INVALID; res = io->status = SPA_STATUS_DRAINED; @@ -1135,8 +1137,11 @@ static void context_drained(void *data, struct pw_impl_node *node) struct stream *impl = data; if (impl->node != node) return; - if (impl->draining && impl->drained) + if (impl->draining && impl->drained) { + impl->draining = false; + impl->io->status = SPA_STATUS_NEED_DATA; call_drained(impl); + } } static const struct pw_context_driver_events context_events = {