node: add master priority

Change node.priority to priority.session to indicate that this
is the priority that the session manager uses to select the node.

Add another priority.master that the core uses to select a master
driver. Keep the driver nodes sorted by master priority.

Let jack always prefer to connect to the master driver nodes.
This commit is contained in:
Wim Taymans 2019-10-22 12:25:25 +02:00
parent fa25900682
commit eb1d675cb0
6 changed files with 33 additions and 9 deletions

View file

@ -144,8 +144,9 @@ static struct alsa_node *alsa_create_node(struct alsa_object *obj, uint32_t id,
priority -= atol(dev) * 16;
priority -= atol(subdev);
if (pw_properties_get(node->props, PW_KEY_NODE_PRIORITY) == NULL) {
pw_properties_setf(node->props, PW_KEY_NODE_PRIORITY, "%d", priority);
if (pw_properties_get(node->props, PW_KEY_PRIORITY_MASTER) == NULL) {
pw_properties_setf(node->props, PW_KEY_PRIORITY_MASTER, "%d", priority);
pw_properties_setf(node->props, PW_KEY_PRIORITY_SESSION, "%d", priority);
}
if (pw_properties_get(node->props, SPA_KEY_NODE_NAME) == NULL) {

View file

@ -509,7 +509,7 @@ handle_node(struct impl *impl, uint32_t id,
else
sess->plugged = SPA_TIMESPEC_TO_NSEC(&impl->now);
if ((str = spa_dict_lookup(props, PW_KEY_NODE_PRIORITY)) != NULL)
if ((str = spa_dict_lookup(props, PW_KEY_PRIORITY_SESSION)) != NULL)
sess->priority = pw_properties_parse_int(str);
else
sess->priority = 0;

View file

@ -72,6 +72,10 @@ extern "C" {
#define PW_KEY_CORE_ID "core.id" /**< the core id */
#define PW_KEY_CORE_MONITORS "core.monitors" /**< the apis monitored by core. */
/* priorities */
#define PW_KEY_PRIORITY_SESSION "priority.session" /**< priority in session manager */
#define PW_KEY_PRIORITY_MASTER "priority.master" /**< priority to be a master */
/* remote keys */
#define PW_KEY_REMOTE_NAME "remote.name" /**< The name of the remote to connect to,
* default env(PIPEWIRE_REMOTE) or pipewire-0 */
@ -115,7 +119,7 @@ extern "C" {
* description. Ex. "Foobar USB Headset" */
#define PW_KEY_NODE_PLUGGED "node.plugged" /**< when the node was created. As a uint64 in
* nanoseconds. */
#define PW_KEY_NODE_PRIORITY "node.priority" /**< priority of node */
#define PW_KEY_NODE_SESSION "node.session" /**< the session id this node is part of */
#define PW_KEY_NODE_EXCLUSIVE "node.exclusive" /**< node wants exclusive access to resources */
#define PW_KEY_NODE_AUTOCONNECT "node.autoconnect" /**< node wants to be automatically connected

View file

@ -548,6 +548,17 @@ static const struct pw_global_events global_events = {
.destroy = global_destroy,
};
static inline void insert_driver(struct pw_core *core, struct pw_node *node)
{
struct pw_node *n, *t;
spa_list_for_each_safe(n, t, &core->driver_list, driver_link) {
if (n->priority_master < node->priority_master)
break;
}
spa_list_append(&n->driver_link, &node->driver_link);
}
SPA_EXPORT
int pw_node_register(struct pw_node *this,
struct pw_properties *properties)
@ -560,7 +571,8 @@ int pw_node_register(struct pw_node *this,
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
PW_KEY_DEVICE_ID,
PW_KEY_NODE_PRIORITY,
PW_KEY_PRIORITY_SESSION,
PW_KEY_PRIORITY_MASTER,
PW_KEY_NODE_DESCRIPTION,
PW_KEY_NODE_NAME,
PW_KEY_NODE_NICK,
@ -593,7 +605,7 @@ int pw_node_register(struct pw_node *this,
spa_list_append(&core->node_list, &this->link);
if (this->driver)
spa_list_append(&core->driver_list, &this->driver_link);
insert_driver(core, this);
this->registered = true;
this->info.id = this->global->id;
@ -711,6 +723,11 @@ static void check_properties(struct pw_node *node)
const char *str;
bool driver, do_recalc = false;
if ((str = pw_properties_get(node->properties, PW_KEY_PRIORITY_MASTER))) {
node->priority_master = pw_properties_parse_int(str);
pw_log_info(NAME" %p: priority master %d", node, node->priority_master);
}
if ((str = pw_properties_get(node->properties, PW_KEY_NODE_NAME))) {
free(node->name);
node->name = strdup(str);
@ -737,7 +754,7 @@ static void check_properties(struct pw_node *node)
node->driver = driver;
if (node->registered) {
if (driver)
spa_list_append(&node->core->driver_list, &node->driver_link);
insert_driver(node->core, node);
else
spa_list_remove(&node->driver_link);
}
@ -1803,7 +1820,8 @@ int pw_node_set_active(struct pw_node *node, bool active)
if (active)
node_activate(node);
pw_core_recalc_graph(node->core);
if (node->registered)
pw_core_recalc_graph(node->core);
}
return 0;
}

View file

@ -437,6 +437,7 @@ struct pw_node {
char *name; /** for debug */
uint32_t priority_master; /** priority for being master driver */
uint32_t spa_flags;
unsigned int registered:1;