mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
autolink: prefer latest plugged device
This commit is contained in:
parent
d2c545be8d
commit
f8222c765e
1 changed files with 29 additions and 6 deletions
|
|
@ -244,6 +244,7 @@ struct find_data {
|
||||||
uint32_t path_id;
|
uint32_t path_id;
|
||||||
const char *media_class;
|
const char *media_class;
|
||||||
struct pw_global *global;
|
struct pw_global *global;
|
||||||
|
uint64_t plugged;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int find_global(void *data, struct pw_global *global)
|
static int find_global(void *data, struct pw_global *global)
|
||||||
|
|
@ -254,6 +255,7 @@ static int find_global(void *data, struct pw_global *global)
|
||||||
struct pw_node *node;
|
struct pw_node *node;
|
||||||
const struct pw_properties *props;
|
const struct pw_properties *props;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
uint64_t plugged;
|
||||||
|
|
||||||
if (pw_global_get_type(global) != impl->t->node)
|
if (pw_global_get_type(global) != impl->t->node)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -271,10 +273,23 @@ static int find_global(void *data, struct pw_global *global)
|
||||||
if (strcmp(str, find->media_class) != 0)
|
if (strcmp(str, find->media_class) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pw_log_debug("module %p: found node '%d'", impl, pw_global_get_id(global));
|
if (find->path_id != SPA_ID_INVALID && global->id != find->path_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
find->global = global;
|
if ((str = pw_properties_get(props, "node.plugged")) != NULL)
|
||||||
return 1;
|
plugged = pw_properties_parse_uint64(str);
|
||||||
|
else
|
||||||
|
plugged = 0;
|
||||||
|
|
||||||
|
pw_log_debug("module %p: found node '%d' %" PRIu64, impl,
|
||||||
|
pw_global_get_id(global), plugged);
|
||||||
|
|
||||||
|
if (find->global == NULL || plugged > find->plugged) {
|
||||||
|
pw_log_debug("module %p: new best %" PRIu64, impl, plugged);
|
||||||
|
find->global = global;
|
||||||
|
find->plugged = plugged;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_node_created(struct node_info *info)
|
static void on_node_created(struct node_info *info)
|
||||||
|
|
@ -285,6 +300,7 @@ static void on_node_created(struct node_info *info)
|
||||||
const char *media, *category, *role, *str;
|
const char *media, *category, *role, *str;
|
||||||
bool exclusive;
|
bool exclusive;
|
||||||
struct find_data find;
|
struct find_data find;
|
||||||
|
enum pw_direction direction;
|
||||||
|
|
||||||
find.info = info;
|
find.info = info;
|
||||||
|
|
||||||
|
|
@ -346,15 +362,22 @@ static void on_node_created(struct node_info *info)
|
||||||
pw_log_debug("module %p: try to find and link to node '%d'", impl, find.path_id);
|
pw_log_debug("module %p: try to find and link to node '%d'", impl, find.path_id);
|
||||||
|
|
||||||
find.global = NULL;
|
find.global = NULL;
|
||||||
if (pw_core_for_each_global(impl->core, find_global, &find) != 1)
|
if (pw_core_for_each_global(impl->core, find_global, &find) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (find.global == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
peer = pw_global_get_object(find.global);
|
peer = pw_global_get_object(find.global);
|
||||||
|
|
||||||
if (strcmp(category, "Capture") == 0)
|
if (strcmp(category, "Capture") == 0)
|
||||||
pw_node_for_each_port(peer, PW_DIRECTION_OUTPUT, on_peer_port, info);
|
direction = PW_DIRECTION_OUTPUT;
|
||||||
if (strcmp(category, "Playback") == 0)
|
if (strcmp(category, "Playback") == 0)
|
||||||
pw_node_for_each_port(peer, PW_DIRECTION_INPUT, on_peer_port, info);
|
direction = PW_DIRECTION_INPUT;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
pw_node_for_each_port(peer, direction, on_peer_port, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue