From 1466982c6063b24dcbf2003876d6efe0db292a64 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 27 Jun 2023 13:00:39 +0200 Subject: [PATCH] stream: add ASYNC flag Add ASYNC flag that sets SPA_NODE_FLAG_ASYNC. This ensure we allocate at least 2 buffers. We need 2 buffers at least because we don't dequeue/queue a buffer in the process function when async and we run out of buffers if we have only 1 buffer. --- src/pipewire/filter.c | 4 +++- src/pipewire/filter.h | 7 +++++++ src/pipewire/stream.c | 2 +- src/pipewire/stream.h | 7 +++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index e306f738c..8efdbd0a0 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1632,7 +1632,9 @@ pw_filter_connect(struct pw_filter *filter, impl->info = SPA_NODE_INFO_INIT(); impl->info.max_input_ports = UINT32_MAX; impl->info.max_output_ports = UINT32_MAX; - impl->info.flags = impl->process_rt ? SPA_NODE_FLAG_RT : 0; + impl->info.flags = SPA_NODE_FLAG_RT; + if (!impl->process_rt || SPA_FLAG_IS_SET(flags, PW_FILTER_FLAG_ASYNC)) + impl->info.flags |= SPA_NODE_FLAG_ASYNC; impl->info.props = &filter->properties->dict; impl->params[NODE_PropInfo] = SPA_PARAM_INFO(SPA_PARAM_PropInfo, 0); impl->params[NODE_Props] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_WRITE); diff --git a/src/pipewire/filter.h b/src/pipewire/filter.h index fc06a8168..bb5081b70 100644 --- a/src/pipewire/filter.h +++ b/src/pipewire/filter.h @@ -109,6 +109,13 @@ enum pw_filter_flags { * needs to be called. This can be used * when the filter depends on processing * of other filters. */ + PW_FILTER_FLAG_ASYNC = (1 << 5), /**< Buffers will not be dequeued/queued from + * the realtime process() function. This is + * assumed when RT_PROCESS is unset but can + * also be the case when the process() function + * does a trigger_process() that will then + * dequeue/queue a buffer from another process() + * function. since 0.3.73 */ }; enum pw_filter_port_flags { diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 52732a2e5..667b94124 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1957,7 +1957,7 @@ pw_stream_connect(struct pw_stream *stream, impl->info.flags = SPA_NODE_FLAG_RT; /* if the callback was not marked RT_PROCESS, we will offload * the process callback in the main thread and we are ASYNC */ - if (!impl->process_rt) + if (!impl->process_rt || SPA_FLAG_IS_SET(flags, PW_STREAM_FLAG_ASYNC)) impl->info.flags |= SPA_NODE_FLAG_ASYNC; impl->info.props = &stream->properties->dict; impl->params[NODE_PropInfo] = SPA_PARAM_INFO(SPA_PARAM_PropInfo, 0); diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index eb607cc67..6ec943b72 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -378,6 +378,13 @@ enum pw_stream_flags { * needs to be called. This can be used * when the output of the stream depends * on input from other streams. */ + PW_STREAM_FLAG_ASYNC = (1 << 10), /**< Buffers will not be dequeued/queued from + * the realtime process() function. This is + * assumed when RT_PROCESS is unset but can + * also be the case when the process() function + * does a trigger_process() that will then + * dequeue/queue a buffer from another process() + * function. since 0.3.73 */ }; /** Create a new unconneced \ref pw_stream