From 182b3c8798311c989989cd2b5387b7fa71e7eb54 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 19 Apr 2022 10:39:38 +0200 Subject: [PATCH] context: rework state calculations We can only call collect_nodes() once because it sets the visited state to true. So, move the unassigned nodes to the fallback driver but when they are passive (nothing is linked), move them back to the NULL driver. This fixes a case where when the fallback driver changes, only some nodes are moved to the new driver (because the other ones were already visited in the collect_nodes() check before). --- src/pipewire/context.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 55f3eba5a..445485190 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -1191,24 +1191,23 @@ again: context, n, n->name, n->active, n->want_driver, target); t = n->want_driver && n->active ? target : NULL; - if (t != NULL && !n->always_process) { - /* first do a check without moving the node to - * the target driver to see if we are passive */ - collect_nodes(context, n); - if (n->passive) - t = NULL; - } - pw_impl_node_set_driver(n, t); - if (t == NULL) { - /* no driver, make sure the node stops */ - ensure_state(n, false); - } - else { + if (t != NULL) { + pw_impl_node_set_driver(n, t); /* we configured a driver, move all linked * nodes to it as well */ if (n->always_process) t->passive = false; collect_nodes(context, n); + if (!n->always_process && n->passive) + /* nothing active and node doesn't need to be + * scheduled, remove from driver again and + * stop */ + t = NULL; + } + if (t == NULL) { + /* no driver, make sure the node stops */ + pw_impl_node_set_driver(n, NULL); + ensure_state(n, false); } } n->visited = false;