From ff84acdf3d40eb8410f6f571abec5a006dd42f77 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 8 Sep 2022 10:31:46 +0200 Subject: [PATCH] impl-node: avoid scheduling the node before added The Start command might be async and we should not schedule the node until the reply has arrived and we have actually added the node to the graph. Otherwise it is possible that the node is scheduled before it could complete the start command. This could be a problem for adapter because it does negotiation and so on in the Start call. See #2677 --- src/pipewire/impl-node.c | 12 ++++++++++++ src/pipewire/private.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/pipewire/impl-node.c b/src/pipewire/impl-node.c index 55851a68e..863f1418c 100644 --- a/src/pipewire/impl-node.c +++ b/src/pipewire/impl-node.c @@ -92,6 +92,8 @@ static void add_node(struct pw_impl_node *this, struct pw_impl_node *driver) struct pw_node_activation_state *dstate, *nstate; struct pw_node_target *t; + this->rt.added = true; + if (this->exported) return; @@ -128,6 +130,8 @@ static void remove_node(struct pw_impl_node *this) struct pw_node_activation_state *dstate, *nstate; struct pw_node_target *t; + this->rt.added = false; + if (this->exported) return; @@ -1078,6 +1082,14 @@ static inline int process_node(void *data) a->status = PW_NODE_ACTIVATION_AWAKE; a->awake_time = SPA_TIMESPEC_TO_NSEC(&ts); + if (!this->rt.added) { + /* FIXME we should try to avoid this by only activating the input + * links after we add the node to the graph. Otherwise there is + * no problem because the target (driver and peers) are not yet + * waiting for our activation */ + pw_log_debug("%p: scheduling non-active node", this); + return -EIO; + } pw_log_trace_fp("%p: process %"PRIu64, this, a->awake_time); /* when transport sync is not supported, just clear the flag */ diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 144e21bf1..71eae8ebb 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -750,6 +750,7 @@ struct pw_impl_node { struct spa_list driver_link; /* our link in driver */ struct ratelimit rate_limit; + unsigned int added:1; /**< the node was add to graph */ } rt; struct spa_fraction current_rate; uint64_t current_quantum;