diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-07-17 17:23:43 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-07-17 17:23:43 +0200 |
commit | 7711c981231112f76f08612e098e91b5b167e9f4 (patch) | |
tree | cc2a60b4d062b6b6cc4b8d87c79aec7a3bd68c70 /pipewire-jack/src/pipewire-jack.c | |
parent | 23788ee6171bc300a844f8229fac08ec25cbdf4c (diff) |
jack: use default sink/source to sort ports
Diffstat (limited to 'pipewire-jack/src/pipewire-jack.c')
-rw-r--r-- | pipewire-jack/src/pipewire-jack.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 5d4ee7b7..f86ef099 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -108,6 +108,7 @@ struct object { union { struct { char name[JACK_CLIENT_NAME_SIZE+1]; + char key[JACK_CLIENT_NAME_SIZE+1]; int32_t priority; uint32_t client_id; } node; @@ -120,6 +121,7 @@ struct object { char name[REAL_JACK_PORT_NAME_SIZE+1]; char alias1[REAL_JACK_PORT_NAME_SIZE+1]; char alias2[REAL_JACK_PORT_NAME_SIZE+1]; + char key[REAL_JACK_PORT_NAME_SIZE+1]; uint32_t type_id; uint32_t node_id; uint32_t port_id; @@ -231,6 +233,9 @@ struct context { struct metadata { struct pw_metadata *proxy; struct spa_hook listener; + + char *default_audio_sink; + char *default_audio_source; }; struct client { @@ -1947,6 +1952,13 @@ static int metadata_property(void *object, uint32_t id, uuid = jack_port_uuid_generate(id); update_property(c, uuid, key, type, value); + if (strcmp(key, "default.audio.sink.name") == 0) { + free(c->metadata->default_audio_sink); + c->metadata->default_audio_sink = value ? strdup(value) : NULL; + } else if (strcmp(key, "default.audio.source.name") == 0) { + free(c->metadata->default_audio_source); + c->metadata->default_audio_source = value ? strdup(value) : NULL; + } return 0; } @@ -1985,6 +1997,10 @@ static void registry_event_global(void *data, uint32_t id, if (ot != NULL && o->node.client_id != ot->node.client_id) { snprintf(o->node.name, sizeof(o->node.name), "%s-%d", str, id); } + if ((str = spa_dict_lookup(props, PW_KEY_NODE_NAME)) == NULL) + str = o->node.name; + snprintf(o->node.key, sizeof(o->node.key), "%s", str); + if ((str = spa_dict_lookup(props, PW_KEY_PRIORITY_MASTER)) != NULL) o->node.priority = pw_properties_parse_int(str); @@ -2057,6 +2073,7 @@ static void registry_event_global(void *data, uint32_t id, goto exit_free; snprintf(o->port.name, sizeof(o->port.name), "%s:%s", ot->node.name, str); + snprintf(o->port.key, sizeof(o->port.key), "%s:%s", ot->node.key, str); o->port.port_id = SPA_ID_INVALID; o->port.priority = ot->node.priority; } @@ -2400,8 +2417,11 @@ int jack_client_close (jack_client_t *client) if (c->registry) pw_proxy_destroy((struct pw_proxy*)c->registry); - if (c->metadata && c->metadata->proxy) + if (c->metadata && c->metadata->proxy) { pw_proxy_destroy((struct pw_proxy*)c->metadata->proxy); + free(c->metadata->default_audio_sink); + free(c->metadata->default_audio_source); + } pw_core_disconnect(c->core); pw_context_destroy(c->context.context); @@ -3911,20 +3931,40 @@ int jack_recompute_total_latency (jack_client_t *client, jack_port_t* port) return 0; } -static int port_compare_func(const void *v1, const void *v2) +static int port_compare_func(const void *v1, const void *v2, void *arg) { + struct client *c = arg; const struct object *const*o1 = v1, *const*o2 = v2; int res; + bool is_cap1, is_cap2, is_def1 = false, is_def2 = false; + + is_cap1 = ((*o1)->port.flags & JackPortIsOutput) == JackPortIsOutput; + is_cap2 = ((*o2)->port.flags & JackPortIsOutput) == JackPortIsOutput; + + if (is_cap1 && c->metadata->default_audio_source != NULL) + is_def1 = strstr((*o1)->port.key, c->metadata->default_audio_source) == (*o1)->port.key; + else if (!is_cap1 && c->metadata->default_audio_sink != NULL) + is_def1 = strstr((*o1)->port.key, c->metadata->default_audio_sink) == (*o1)->port.key; + + if (is_cap2 && c->metadata->default_audio_source != NULL) + is_def2 = strstr((*o2)->port.key, c->metadata->default_audio_source) == (*o2)->port.key; + else if (!is_cap2 && c->metadata->default_audio_sink != NULL) + is_def2 = strstr((*o2)->port.key, c->metadata->default_audio_sink) == (*o2)->port.key; if ((*o1)->port.type_id != (*o2)->port.type_id) res = (*o1)->port.type_id - (*o2)->port.type_id; + else if ((is_cap1 || is_cap2) && is_cap1 != is_cap2) + res = is_cap2 - is_cap1; + else if ((is_def1 || is_def2) && is_def1 != is_def2) + res = is_def2 - is_def1; else if ((*o1)->port.priority != (*o2)->port.priority) res = (*o2)->port.priority - (*o1)->port.priority; else if ((res = strcmp((*o1)->port.alias1, (*o2)->port.alias1) == 0)) res = (*o1)->id - (*o2)->id; - pw_log_debug("port type:%d<->%d prio:%d<->%d id:%d<->%d res:%d", + pw_log_debug("port type:%d<->%d def:%d<->%d prio:%d<->%d id:%d<->%d res:%d", (*o1)->port.type_id, (*o2)->port.type_id, + is_def1, is_def2, (*o1)->port.priority, (*o2)->port.priority, (*o1)->id, (*o2)->id, res); return res; @@ -3991,7 +4031,7 @@ const char ** jack_get_ports (jack_client_t *client, pthread_mutex_unlock(&c->context.lock); if (count > 0) { - qsort(tmp, count, sizeof(struct object *), port_compare_func); + qsort_r(tmp, count, sizeof(struct object *), port_compare_func, c); res = malloc(sizeof(char*) * (count + 1)); for (i = 0; i < count; i++) |