diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c index 84ce10132..0d0424fc3 100644 --- a/pipewire-pulseaudio/src/context.c +++ b/pipewire-pulseaudio/src/context.c @@ -170,14 +170,6 @@ const char *pa_context_find_global_name(pa_context *c, uint32_t id) return name; } -static inline bool pa_endswith(const char *s, const char *sfx) -{ - size_t l1, l2; - l1 = strlen(s); - l2 = strlen(sfx); - return l1 >= l2 && pa_streq(s + l1 - l2, sfx); -} - struct global *pa_context_find_global_by_name(pa_context *c, uint32_t mask, const char *name) { struct global *g; diff --git a/pipewire-pulseaudio/src/internal.h b/pipewire-pulseaudio/src/internal.h index 7f76bda99..f3020503a 100644 --- a/pipewire-pulseaudio/src/internal.h +++ b/pipewire-pulseaudio/src/internal.h @@ -513,6 +513,8 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv); struct timeval* pa_rtclock_to_wallclock(struct timeval *tv); struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, bool rtclock); +bool pa_endswith(const char *s, const char *sfx); + pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb, size_t userdata_size); void pa_operation_done(pa_operation *o); int pa_operation_sync(pa_operation *o); diff --git a/pipewire-pulseaudio/src/stream.c b/pipewire-pulseaudio/src/stream.c index a5fe71f77..18fff4687 100644 --- a/pipewire-pulseaudio/src/stream.c +++ b/pipewire-pulseaudio/src/stream.c @@ -848,7 +848,6 @@ 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; @@ -956,24 +955,19 @@ static int create_stream(pa_stream_direction_t direction, else devid = PW_ID_ANY; - if (dev == NULL) { - if ((str = getenv("PIPEWIRE_NODE")) != NULL) - devid = atoi(str); + if (dev == NULL && devid == PW_ID_ANY) { + dev = getenv("PIPEWIRE_NODE"); } - 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) + else if (dev != NULL && devid == PW_ID_ANY) { + if ((devid = atoi(dev)) == 0) devid = PW_ID_ANY; + else if (devid & PA_IDX_FLAG_MONITOR) + devid &= PA_IDX_MASK_MONITOR; + + if (devid == PW_ID_ANY) { + if (pa_endswith(dev, ".monitor")) + dev = strndupa(dev, strlen(dev) - 8); + } } if ((str = pa_proplist_gets(s->proplist, PA_PROP_MEDIA_ROLE)) != NULL) { diff --git a/pipewire-pulseaudio/src/util.c b/pipewire-pulseaudio/src/util.c index 4fe8c5d2c..66d9baa33 100644 --- a/pipewire-pulseaudio/src/util.c +++ b/pipewire-pulseaudio/src/util.c @@ -26,6 +26,8 @@ #include +#include "internal.h" + #define PA_PATH_SEP_CHAR '/' SPA_EXPORT @@ -112,3 +114,11 @@ int pa_msleep(unsigned long t) return nanosleep(&ts, NULL); } + +bool pa_endswith(const char *s, const char *sfx) +{ + size_t l1, l2; + l1 = strlen(s); + l2 = strlen(sfx); + return l1 >= l2 && pa_streq(s + l1 - l2, sfx); +}