pulse: find linked endpoints

Set the stream node object-id as the node.id on the endpoint so that
the pulse api can find the linked endpoint.
This commit is contained in:
Wim Taymans 2019-11-15 18:21:04 +01:00
parent 709a52e286
commit 8c43ebaf3e
6 changed files with 35 additions and 40 deletions

View file

@ -150,21 +150,19 @@ struct global *pa_context_find_linked(pa_context *c, uint32_t idx)
struct global *g, *f; struct global *g, *f;
spa_list_for_each(g, &c->globals, link) { spa_list_for_each(g, &c->globals, link) {
uint32_t src_endpoint_id, dst_endpoint_id; if (g->type != PW_TYPE_INTERFACE_EndpointLink)
if (g->type != PW_TYPE_INTERFACE_Link)
continue; continue;
src_endpoint_id = g->link_info.src->stream_info.endpoint_id; pw_log_debug("context %p: %p %d %d:%d %d:%d", c, g, idx,
dst_endpoint_id = g->link_info.dst->stream_info.endpoint_id; g->link_info.output->id, g->link_info.output->endpoint_info.node_id,
g->link_info.input->id, g->link_info.input->endpoint_info.node_id);
pw_log_debug("context %p: %p %d %d %d", c, g, idx, if (g->link_info.input->id == idx ||
src_endpoint_id, dst_endpoint_id); g->link_info.input->endpoint_info.node_id == idx)
f = g->link_info.output;
if (src_endpoint_id == idx) else if (g->link_info.output->id == idx ||
f = pa_context_find_global(c, dst_endpoint_id); g->link_info.output->endpoint_info.node_id == idx)
else if (dst_endpoint_id == idx) f = g->link_info.input;
f = pa_context_find_global(c, src_endpoint_id);
else else
continue; continue;
@ -581,9 +579,8 @@ static const struct pw_proxy_events proxy_events = {
static int set_mask(pa_context *c, struct global *g) static int set_mask(pa_context *c, struct global *g)
{ {
const char *str; const char *str;
struct global *f; const void *events = NULL;
const void *events = NULL; pw_destroy_t destroy;
pw_destroy_t destroy;
uint32_t client_version; uint32_t client_version;
switch (g->type) { switch (g->type) {
@ -645,6 +642,8 @@ static int set_mask(pa_context *c, struct global *g)
g->endpoint_info.client_id = atoi(str); g->endpoint_info.client_id = atoi(str);
if ((str = pw_properties_get(g->props, PW_KEY_DEVICE_ID)) != NULL) if ((str = pw_properties_get(g->props, PW_KEY_DEVICE_ID)) != NULL)
g->endpoint_info.device_id = atoi(str); g->endpoint_info.device_id = atoi(str);
if ((str = pw_properties_get(g->props, PW_KEY_NODE_ID)) != NULL)
g->endpoint_info.node_id = atoi(str);
events = &endpoint_events; events = &endpoint_events;
client_version = PW_VERSION_ENDPOINT_PROXY; client_version = PW_VERSION_ENDPOINT_PROXY;
@ -661,7 +660,6 @@ static int set_mask(pa_context *c, struct global *g)
pw_log_warn("endpoint stream %d without "PW_KEY_ENDPOINT_ID, g->id); pw_log_warn("endpoint stream %d without "PW_KEY_ENDPOINT_ID, g->id);
return 0; return 0;
} }
/* streams get transformed into profiles on the device */ /* streams get transformed into profiles on the device */
pw_log_debug("found endpoint stream %d", g->id); pw_log_debug("found endpoint stream %d", g->id);
break; break;
@ -685,28 +683,22 @@ static int set_mask(pa_context *c, struct global *g)
break; break;
case PW_TYPE_INTERFACE_EndpointLink: case PW_TYPE_INTERFACE_EndpointLink:
if ((str = pw_properties_get(g->props, PW_KEY_LINK_OUTPUT_PORT)) == NULL) if ((str = pw_properties_get(g->props, PW_KEY_ENDPOINT_LINK_OUTPUT_ENDPOINT)) == NULL)
return 0; return 0;
g->link_info.src = pa_context_find_global(c, pw_properties_parse_int(str)); g->link_info.output = pa_context_find_global(c, pw_properties_parse_int(str));
if ((str = pw_properties_get(g->props, PW_KEY_LINK_INPUT_PORT)) == NULL) if ((str = pw_properties_get(g->props, PW_KEY_ENDPOINT_LINK_INPUT_ENDPOINT)) == NULL)
return 0; return 0;
g->link_info.dst = pa_context_find_global(c, pw_properties_parse_int(str)); g->link_info.input = pa_context_find_global(c, pw_properties_parse_int(str));
if (g->link_info.src == NULL || g->link_info.dst == NULL) if (g->link_info.output == NULL || g->link_info.input == NULL)
return 0; return 0;
pw_log_debug("link %d:%d->%d:%d", pw_log_debug("link %d->%d", g->link_info.output->id, g->link_info.input->id);
g->link_info.src->stream_info.endpoint_id,
g->link_info.src->id,
g->link_info.dst->stream_info.endpoint_id,
g->link_info.dst->id);
if ((f = pa_context_find_global(c, g->link_info.src->stream_info.endpoint_id)) != NULL && if (!g->link_info.output->init)
!f->init) emit_event(c, g->link_info.output, PA_SUBSCRIPTION_EVENT_CHANGE);
emit_event(c, f, PA_SUBSCRIPTION_EVENT_CHANGE); if (!g->link_info.input->init)
if ((f = pa_context_find_global(c, g->link_info.dst->stream_info.endpoint_id)) != NULL && emit_event(c, g->link_info.input, PA_SUBSCRIPTION_EVENT_CHANGE);
!f->init)
emit_event(c, f, PA_SUBSCRIPTION_EVENT_CHANGE);
break; break;
@ -739,12 +731,11 @@ static inline void insert_global(pa_context *c, struct global *global)
struct global *g, *t; struct global *g, *t;
spa_list_for_each_safe(g, t, &c->globals, link) { spa_list_for_each_safe(g, t, &c->globals, link) {
if (g->priority_session < global->priority_session) { if (g->priority_session <= global->priority_session) {
g = spa_list_prev(g, link);
break; break;
} }
} }
spa_list_prepend(&g->link, &global->link); spa_list_append(&g->link, &global->link);
} }
static void registry_event_global(void *data, uint32_t id, static void registry_event_global(void *data, uint32_t id,

View file

@ -245,10 +245,10 @@ struct global {
struct spa_hook object_listener; struct spa_hook object_listener;
union { union {
/* for links */ /* for links, globals are endpoints */
struct { struct {
struct global *src; struct global *output;
struct global *dst; struct global *input;
} link_info; } link_info;
struct { struct {
uint32_t endpoint_id; uint32_t endpoint_id;
@ -262,6 +262,7 @@ struct global {
uint32_t n_channel_volumes; uint32_t n_channel_volumes;
float channel_volumes[SPA_AUDIO_MAX_CHANNELS]; float channel_volumes[SPA_AUDIO_MAX_CHANNELS];
uint32_t device_id; uint32_t device_id;
uint32_t node_id;
} endpoint_info; } endpoint_info;
/* for devices */ /* for devices */
struct { struct {

View file

@ -1797,7 +1797,7 @@ static void source_output_callback(struct source_output_data *d)
if (name == NULL && info->props) { if (name == NULL && info->props) {
if ((name = spa_dict_lookup(info->props, PW_KEY_MEDIA_NAME)) == NULL && if ((name = spa_dict_lookup(info->props, PW_KEY_MEDIA_NAME)) == NULL &&
(name = spa_dict_lookup(info->props, PW_KEY_APP_NAME)) == NULL && (name = spa_dict_lookup(info->props, PW_KEY_APP_NAME)) == NULL &&
(name = spa_dict_lookup(info->props, PW_KEY_NODE_NAME)) == NULL) (name = spa_dict_lookup(info->props, PW_KEY_ENDPOINT_NAME)) == NULL)
name = NULL; name = NULL;
} }
if (name == NULL) if (name == NULL)

View file

@ -208,7 +208,7 @@ static void configure_device(pa_stream *s)
s->device_index = g->id; s->device_index = g->id;
} }
if ((str = pw_properties_get(g->props, PW_KEY_NODE_NAME)) == NULL) if ((str = pw_properties_get(g->props, PW_KEY_ENDPOINT_NAME)) == NULL)
s->device_name = strdup("unknown"); s->device_name = strdup("unknown");
else else
s->device_name = strdup(str); s->device_name = strdup(str);

View file

@ -242,6 +242,8 @@ static struct client_endpoint *make_endpoint(struct node *node)
pw_properties_set(props, PW_KEY_MEDIA_CLASS, media_class); pw_properties_set(props, PW_KEY_MEDIA_CLASS, media_class);
if ((name = spa_dict_lookup(dict, PW_KEY_MEDIA_NAME)) != NULL) if ((name = spa_dict_lookup(dict, PW_KEY_MEDIA_NAME)) != NULL)
pw_properties_set(props, PW_KEY_ENDPOINT_NAME, name); pw_properties_set(props, PW_KEY_ENDPOINT_NAME, name);
if ((str = spa_dict_lookup(dict, PW_KEY_OBJECT_ID)) != NULL)
pw_properties_set(props, PW_KEY_NODE_ID, str);
if ((str = spa_dict_lookup(dict, PW_KEY_NODE_AUTOCONNECT)) != NULL) if ((str = spa_dict_lookup(dict, PW_KEY_NODE_AUTOCONNECT)) != NULL)
pw_properties_set(props, PW_KEY_ENDPOINT_AUTOCONNECT, str); pw_properties_set(props, PW_KEY_ENDPOINT_AUTOCONNECT, str);
if ((str = spa_dict_lookup(dict, PW_KEY_NODE_TARGET)) != NULL) if ((str = spa_dict_lookup(dict, PW_KEY_NODE_TARGET)) != NULL)

View file

@ -302,6 +302,7 @@ int endpoint_init(struct endpoint *this,
PW_KEY_FACTORY_ID, PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID, PW_KEY_CLIENT_ID,
PW_KEY_DEVICE_ID, PW_KEY_DEVICE_ID,
PW_KEY_NODE_ID,
PW_KEY_MEDIA_CLASS, PW_KEY_MEDIA_CLASS,
PW_KEY_PRIORITY_SESSION, PW_KEY_PRIORITY_SESSION,
PW_KEY_ENDPOINT_NAME, PW_KEY_ENDPOINT_NAME,