pulse: avoid node lookup when connecting

We can use the node name directly if we strip the .monitor suffix
or remove the MONITOR flag form the name/id.
This commit is contained in:
Wim Taymans 2020-10-24 16:58:01 +02:00
parent ec860d64cf
commit 8ac9ce7947
4 changed files with 23 additions and 25 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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) {

View file

@ -26,6 +26,8 @@
#include <pulse/util.h>
#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);
}