From 99482f016646cd858552f34568ac3aed0ca2abe6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 8 Mar 2023 16:55:00 +0100 Subject: [PATCH] impl-node: implement mode node.passive property values The node.passive property can actually take true, in and out as values to mark what ports to make passive. Keep track of what port direction to make passive. Set the passive property also on ports and make all port inherit the property from the node first (based on direction) and then use the new port.passive property as an override. Make the link use the passive property from the ports that it links to check the passive state of the link. --- src/pipewire/impl-link.c | 2 +- src/pipewire/impl-node.c | 10 +++++++++- src/pipewire/impl-port.c | 10 +++++++++- src/pipewire/keys.h | 1 + src/pipewire/private.h | 4 +++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/pipewire/impl-link.c b/src/pipewire/impl-link.c index 11a79d87b..23e4a3cd1 100644 --- a/src/pipewire/impl-link.c +++ b/src/pipewire/impl-link.c @@ -1203,7 +1203,7 @@ 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_node->passive | input_node->passive; + this->passive = str ? spa_atob(str) : output->passive | input->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 9301d250a..182bccdbf 100644 --- a/src/pipewire/impl-node.c +++ b/src/pipewire/impl-node.c @@ -947,7 +947,15 @@ static void check_properties(struct pw_impl_node *node) recalc_reason = "link group changed"; } - node->passive = pw_properties_get_bool(node->properties, PW_KEY_NODE_PASSIVE, false); + if ((str = pw_properties_get(node->properties, PW_KEY_NODE_PASSIVE)) == NULL) + str = "false"; + if (spa_streq(str, "out")) + node->out_passive = true; + else if (spa_streq(str, "in")) + node->in_passive = true; + else + node->in_passive = node->out_passive = spa_atob(str); + node->want_driver = pw_properties_get_bool(node->properties, PW_KEY_NODE_WANT_DRIVER, false); node->always_process = pw_properties_get_bool(node->properties, PW_KEY_NODE_ALWAYS_PROCESS, false); diff --git a/src/pipewire/impl-port.c b/src/pipewire/impl-port.c index 249f11831..60b1ba512 100644 --- a/src/pipewire/impl-port.c +++ b/src/pipewire/impl-port.c @@ -999,10 +999,18 @@ int pw_impl_port_add(struct pw_impl_port *port, struct pw_impl_node *node) } else { dir = port->direction == PW_DIRECTION_INPUT ? "in" : "out"; - } pw_properties_set(port->properties, PW_KEY_PORT_DIRECTION, dir); + /* inherit passive state from parent node */ + if (port->direction == PW_DIRECTION_INPUT) + port->passive = node->in_passive; + else + port->passive = node->out_passive; + /* override with specific port property if available */ + port->passive = pw_properties_get_bool(port->properties, PW_KEY_PORT_PASSIVE, + port->passive); + if (media_class != NULL && (strstr(media_class, "Sink") != NULL || strstr(media_class, "Source") != NULL)) diff --git a/src/pipewire/keys.h b/src/pipewire/keys.h index 87e1df868..faae99b53 100644 --- a/src/pipewire/keys.h +++ b/src/pipewire/keys.h @@ -195,6 +195,7 @@ extern "C" { #define PW_KEY_PORT_CACHE_PARAMS "port.cache-params" /**< cache the node port params */ #define PW_KEY_PORT_EXTRA "port.extra" /**< api specific extra port info, API name * should be prefixed. "jack:flags:56" */ +#define PW_KEY_PORT_PASSIVE "port.passive" /**< the ports wants passive links, since 0.3.67 */ /** link properties */ #define PW_KEY_LINK_ID "link.id" /**< a link id */ diff --git a/src/pipewire/private.h b/src/pipewire/private.h index a7b84f0a6..3d95922eb 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -686,7 +686,8 @@ struct pw_impl_node { * is selected to drive the graph */ unsigned int visited:1; /**< for sorting */ unsigned int want_driver:1; /**< this node wants to be assigned to a driver */ - unsigned int passive:1; /**< node links should be passive */ + unsigned int in_passive:1; /**< node input links should be passive */ + unsigned int out_passive:1; /**< node output links should be passive */ unsigned int runnable:1; /**< node is runnable */ unsigned int freewheel:1; /**< if this is the freewheel driver */ unsigned int loopchecked:1; /**< for feedback loop checking */ @@ -859,6 +860,7 @@ struct pw_impl_port { } rt; /**< data only accessed from the data thread */ unsigned int added:1; unsigned int destroying:1; + unsigned int passive:1; int busy_count; struct spa_latency_info latency[2]; /**< latencies */