From f28c30d526f897d55a49426d66124bada04d560b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 28 Mar 2023 18:10:20 +0200 Subject: [PATCH] impl-link: only make passive links with suspendable peers Only make a passive link when one of the peers is passive and the other one can be suspended or when both are explicitly passive. This avoid making passive links between a sink/source pair. It also avoid making passive links between two streams if they are not explicitly marked as passive. It does allow making passive links between a passive stream and a sink/source or between two passive streams. --- src/pipewire/impl-link.c | 5 ++++- src/pipewire/impl-node.c | 6 ++++++ src/pipewire/private.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pipewire/impl-link.c b/src/pipewire/impl-link.c index a82a1fe02..e05c14050 100644 --- a/src/pipewire/impl-link.c +++ b/src/pipewire/impl-link.c @@ -1203,7 +1203,10 @@ struct pw_impl_link *pw_context_create_link(struct pw_context *context, /* passive means that this link does not make the nodes active */ str = pw_properties_get(properties, PW_KEY_LINK_PASSIVE); - this->passive = str ? spa_atob(str) : output->passive | input->passive; + this->passive = str ? spa_atob(str) : + (output->passive && input_node->can_suspend) || + (input->passive && output_node->can_suspend) || + (input->passive && output->passive); if (this->passive && str == NULL) pw_properties_set(properties, PW_KEY_LINK_PASSIVE, "true"); diff --git a/src/pipewire/impl-node.c b/src/pipewire/impl-node.c index 6ab851b04..956540467 100644 --- a/src/pipewire/impl-node.c +++ b/src/pipewire/impl-node.c @@ -956,6 +956,12 @@ static void check_properties(struct pw_impl_node *node) recalc_reason = "link group changed"; } + if ((str = pw_properties_get(node->properties, PW_KEY_MEDIA_CLASS)) != NULL && + (strstr(str, "/Sink") != NULL || strstr(str, "/Source") != NULL)) { + node->can_suspend = true; + } else { + node->can_suspend = false; + } if ((str = pw_properties_get(node->properties, PW_KEY_NODE_PASSIVE)) == NULL) str = "false"; if (spa_streq(str, "out")) diff --git a/src/pipewire/private.h b/src/pipewire/private.h index ad4afd1e8..5303c5b77 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -705,6 +705,7 @@ struct pw_impl_node { unsigned int forced_rate:1; unsigned int trigger:1; /**< has the TRIGGER property and needs an extra * trigger to start processing. */ + unsigned int can_suspend:1; uint32_t port_user_data_size; /**< extra size for port user data */