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.
This commit is contained in:
Wim Taymans 2021-02-25 12:05:28 +01:00
parent 96fda265e0
commit 1a12d6082a

View file

@ -833,10 +833,12 @@ again:
/* pop new buffer */ /* pop new buffer */
if ((b = pop_queue(impl, &impl->queued)) != NULL) { if ((b = pop_queue(impl, &impl->queued)) != NULL) {
impl->drained = false;
io->buffer_id = b->id; io->buffer_id = b->id;
res = io->status = SPA_STATUS_HAVE_DATA; res = io->status = SPA_STATUS_HAVE_DATA;
pw_log_trace(NAME" %p: pop %d %p", stream, b->id, io); 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; impl->drained = true;
io->buffer_id = SPA_ID_INVALID; io->buffer_id = SPA_ID_INVALID;
res = io->status = SPA_STATUS_DRAINED; 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; struct stream *impl = data;
if (impl->node != node) if (impl->node != node)
return; return;
if (impl->draining && impl->drained) if (impl->draining && impl->drained) {
impl->draining = false;
impl->io->status = SPA_STATUS_NEED_DATA;
call_drained(impl); call_drained(impl);
}
} }
static const struct pw_context_driver_events context_events = { static const struct pw_context_driver_events context_events = {