impl-port: make passive mode as an enum

Hopefully easier to understand.
This commit is contained in:
Wim Taymans 2026-03-12 13:46:49 +01:00
parent ad195b289a
commit 45e3af5cdc
4 changed files with 32 additions and 56 deletions

View file

@ -105,13 +105,9 @@ static int ensure_state(struct pw_impl_node *node, bool running)
state = PW_NODE_STATE_IDLE;
return pw_impl_node_set_state(node, state);
}
/* Make a node runnable. Peer nodes are also made runnable when the passive_into state
* of the port is false, which is only when the port is folow or non-passive.
*
* away into
* false : false false
* true : true true <- passive_into peer ports skipped
* follow : true false
/* Make a node runnable. Peer nodes are also made runnable when the passive_mode
* of the port is false or follow.
*
* A (*) -> B if A running -> B set to running
* A (*) -> (f) B if A running -> B set to running
@ -144,8 +140,8 @@ static void make_runnable(struct pw_context *context, struct pw_impl_node *node)
spa_list_for_each(l, &p->links, output_link) {
n = l->input->node;
pw_log_trace(" out-port %p: link %p passive:%d prepared:%d active:%d runn:%d", p,
l, l->input->passive_into, l->prepared, n->active, n->runnable);
if (!n->active || l->input->passive_into)
l, l->input->passive_mode, l->prepared, n->active, n->runnable);
if (!n->active || l->input->passive_mode == PASSIVE_MODE_TRUE)
continue;
pw_impl_link_prepare(l);
if (!l->prepared)
@ -158,8 +154,8 @@ static void make_runnable(struct pw_context *context, struct pw_impl_node *node)
spa_list_for_each(l, &p->links, input_link) {
n = l->output->node;
pw_log_trace(" in-port %p: link %p passive:%d prepared:%d active:%d runn:%d", p,
l, l->output->passive_into, l->prepared, n->active, n->runnable);
if (!n->active || l->output->passive_into)
l, l->output->passive_mode, l->prepared, n->active, n->runnable);
if (!n->active || l->output->passive_mode == PASSIVE_MODE_TRUE)
continue;
pw_impl_link_prepare(l);
if (!l->prepared)
@ -189,15 +185,7 @@ static void make_runnable(struct pw_context *context, struct pw_impl_node *node)
/* check if a node and its peer can run.
*
* When looking at a node we only consider the non passive_away links, the
* passive_away links from the node don't make the peer or node runnable.
*
* away into
* false : false false <- !passive_away ports followed
* true : true true
* follow : true false
*
* A port only has a passive_away link when the port is set to non-passive.
* Only consider ports that have a PASSIVE_MODE_FALSE link.
* All other port modes don't make A and B runnable.
*
* A -> B A + B both set to running
@ -224,8 +212,8 @@ static void check_runnable(struct pw_context *context, struct pw_impl_node *node
/* the peer needs to be active and we are linked to it
* with a non-passive link */
pw_log_trace(" out-port %p: link %p passive:%d prepared:%d active:%d", p,
l, p->passive_away, l->prepared, n->active);
if (!n->active || p->passive_away)
l, p->passive_mode, l->prepared, n->active);
if (!n->active || p->passive_mode != PASSIVE_MODE_FALSE)
continue;
/* explicitly prepare the link in case it was suspended */
pw_impl_link_prepare(l);
@ -239,8 +227,8 @@ static void check_runnable(struct pw_context *context, struct pw_impl_node *node
spa_list_for_each(l, &p->links, input_link) {
n = l->output->node;
pw_log_trace(" in-port %p: link %p passive:%d prepared:%d active:%d", p,
l, p->passive_away, l->prepared, n->active);
if (!n->active || p->passive_away)
l, p->passive_mode, l->prepared, n->active);
if (!n->active || p->passive_mode != PASSIVE_MODE_FALSE)
continue;
pw_impl_link_prepare(l);
if (!l->prepared)

View file

@ -1270,32 +1270,25 @@ static void check_properties(struct pw_impl_node *node)
}
if (spa_streq(str, "out")) {
node->passive_away[SPA_DIRECTION_OUTPUT] = true;
node->passive_into[SPA_DIRECTION_OUTPUT]= true;
node->passive_mode[SPA_DIRECTION_OUTPUT] = PASSIVE_MODE_TRUE;
}
if (spa_streq(str, "out-follow")) {
node->passive_away[SPA_DIRECTION_OUTPUT] = true;
node->passive_into[SPA_DIRECTION_OUTPUT] = false;
node->passive_mode[SPA_DIRECTION_OUTPUT] = PASSIVE_MODE_FOLLOW;
}
else if (spa_streq(str, "in")) {
node->passive_away[SPA_DIRECTION_INPUT] = true;
node->passive_into[SPA_DIRECTION_INPUT]= true;
node->passive_mode[SPA_DIRECTION_INPUT] = PASSIVE_MODE_TRUE;
}
else if (spa_streq(str, "in-follow")) {
node->passive_away[SPA_DIRECTION_INPUT] = true;
node->passive_into[SPA_DIRECTION_INPUT] = false;
node->passive_mode[SPA_DIRECTION_INPUT] = PASSIVE_MODE_FOLLOW;
}
else if (spa_streq(str, "follow")) {
node->passive_away[SPA_DIRECTION_INPUT] = true;
node->passive_into[SPA_DIRECTION_INPUT] = false;
node->passive_away[SPA_DIRECTION_OUTPUT] = true;
node->passive_into[SPA_DIRECTION_OUTPUT] = false;
node->passive_mode[SPA_DIRECTION_INPUT] = PASSIVE_MODE_FOLLOW;
node->passive_mode[SPA_DIRECTION_OUTPUT] = PASSIVE_MODE_FOLLOW;
}
else {
node->passive_away[SPA_DIRECTION_OUTPUT] =
node->passive_into[SPA_DIRECTION_OUTPUT] =
node->passive_away[SPA_DIRECTION_INPUT] =
node->passive_into[SPA_DIRECTION_INPUT] = spa_atob(str);
node->passive_mode[SPA_DIRECTION_OUTPUT] =
node->passive_mode[SPA_DIRECTION_INPUT] =
spa_atob(str) ? PASSIVE_MODE_TRUE : PASSIVE_MODE_FALSE;
}
node->want_driver = pw_properties_get_bool(node->properties, PW_KEY_NODE_WANT_DRIVER, false);

View file

@ -540,21 +540,14 @@ static int check_properties(struct pw_impl_port *port)
if ((str = pw_properties_get(port->properties, PW_KEY_PORT_PASSIVE)) == NULL) {
/* inherit passive state from parent node */
port->passive_into = node->passive_into[port->direction];
port->passive_away = node->passive_away[port->direction];
port->passive_mode = node->passive_mode[port->direction];
} else {
if (spa_streq(str, "true")) {
port->passive_into = true;
port->passive_away = true;
}
else if (spa_streq(str, "follow")) {
port->passive_into = false;
port->passive_away = true;
if (spa_streq(str, "follow")) {
port->passive_mode = PASSIVE_MODE_FOLLOW;
} else {
port->passive_into = false;
port->passive_away = false;
port->passive_mode = spa_atob(str) ?
PASSIVE_MODE_TRUE : PASSIVE_MODE_FALSE;
}
}
if (media_class != NULL &&

View file

@ -785,8 +785,10 @@ struct pw_impl_node {
unsigned int exclusive:1; /**< ports can only be linked once */
unsigned int reliable:1; /**< ports need reliable tee */
bool passive_away[2]; /**< node input links should be passive */
bool passive_into[2]; /**< node input links should be passive */
#define PASSIVE_MODE_FALSE 0
#define PASSIVE_MODE_TRUE 1
#define PASSIVE_MODE_FOLLOW 2
bool passive_mode[2]; /**< node input links should be passive */
uint32_t transport; /**< latest transport request */
@ -961,9 +963,9 @@ struct pw_impl_port {
struct spa_list node_link;
bool added;
} rt; /**< data only accessed from the data thread */
int passive_mode;
unsigned int destroying:1;
unsigned int passive_into:1;
unsigned int passive_away:1;
unsigned int auto_path:1; /* path was automatically generated */
unsigned int auto_name:1; /* name was automatically generated */
unsigned int auto_alias:1; /* alias was automatically generated */