diff --git a/pipewire-pulseaudio/src/stream.c b/pipewire-pulseaudio/src/stream.c index b998220c2..a5fe71f77 100644 --- a/pipewire-pulseaudio/src/stream.c +++ b/pipewire-pulseaudio/src/stream.c @@ -848,6 +848,7 @@ static int create_stream(pa_stream_direction_t direction, struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); const char *str; uint32_t devid, n_items; + struct global *g; struct spa_dict_item items[7]; bool monitor, no_remix; const char *name; @@ -955,8 +956,25 @@ static int create_stream(pa_stream_direction_t direction, else devid = PW_ID_ANY; - if (dev == NULL) - dev = getenv("PIPEWIRE_NODE"); + if (dev == NULL) { + if ((str = getenv("PIPEWIRE_NODE")) != NULL) + devid = atoi(str); + } + else if (devid == PW_ID_ANY) { + uint32_t mask; + + if (direction == PA_STREAM_PLAYBACK) + mask = PA_SUBSCRIPTION_MASK_SINK; + else if (direction == PA_STREAM_RECORD) + mask = PA_SUBSCRIPTION_MASK_SOURCE; + else + mask = 0; + + if ((g = pa_context_find_global_by_name(s->context, mask, dev)) != NULL) + devid = g->id; + else if ((devid = atoi(dev)) == 0) + devid = PW_ID_ANY; + } if ((str = pa_proplist_gets(s->proplist, PA_PROP_MEDIA_ROLE)) != NULL) { if (strcmp(str, "video") == 0)