From c8850f876631b7f5130aefe2927364598346ddf6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 24 Jan 2023 17:39:54 +0100 Subject: [PATCH] env vars should override everything Always first use the env var and then check the properties. So that PIPEWIRE_CORE=pipewire-1 PIPEWIRE_REMOTE=pipewire-1 make run runs everything on pipewire-1 sockets regardless of the config files. Also PIPEWIRE_NODE always needs to be taken into account first. --- pipewire-alsa/alsa-plugins/ctl_pipewire.c | 4 ---- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 4 ---- src/modules/module-protocol-native.c | 10 ++++------ src/modules/module-protocol-native/local-socket.c | 7 +++---- src/modules/module-protocol-pulse/utils.c | 5 ++--- src/pipewire/stream.c | 7 ++++--- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/ctl_pipewire.c b/pipewire-alsa/alsa-plugins/ctl_pipewire.c index ccb04ae32..61394e2ff 100644 --- a/pipewire-alsa/alsa-plugins/ctl_pipewire.c +++ b/pipewire-alsa/alsa-plugins/ctl_pipewire.c @@ -1418,10 +1418,6 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pipewire) if (str != NULL) pw_properties_update_string(ctl->props, str, strlen(str)); - str = getenv("PIPEWIRE_REMOTE"); - if (str != NULL && str[0] != '\0') - pw_properties_set(ctl->props, PW_KEY_REMOTE_NAME, str); - if ((str = pw_properties_get(ctl->props, "alsa.volume-method")) == NULL) str = DEFAULT_VOLUME_METHOD; diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index 8129ce207..dc0cd8162 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -1158,10 +1158,6 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp, if (str != NULL && str[0]) pw_properties_set(pw->props, PW_KEY_TARGET_OBJECT, str); - str = getenv("PIPEWIRE_REMOTE"); - if (str != NULL && str[0]) - pw_properties_set(pw->props, PW_KEY_REMOTE_NAME, str); - node_name = pw_properties_get(pw->props, PW_KEY_NODE_NAME); if (pw_properties_get(pw->props, PW_KEY_MEDIA_NAME) == NULL) pw_properties_set(pw->props, PW_KEY_MEDIA_NAME, node_name); diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 7604da901..6fdc79b47 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -1287,10 +1287,9 @@ get_server_name(const struct spa_dict *props) { const char *name = NULL; - if (props) + name = getenv("PIPEWIRE_CORE"); + if (name == NULL && props != NULL) name = spa_dict_lookup(props, PW_KEY_CORE_NAME); - if (name == NULL) - name = getenv("PIPEWIRE_CORE"); if (name == NULL) name = PW_DEFAULT_REMOTE; return name; @@ -1466,10 +1465,9 @@ static int need_server(struct pw_context *context, const struct spa_dict *props) { const char *val = NULL; - if (props) + val = getenv("PIPEWIRE_DAEMON"); + if (val == NULL && props != NULL) val = spa_dict_lookup(props, PW_KEY_CORE_DAEMON); - if (val == NULL) - val = getenv("PIPEWIRE_DAEMON"); if (val && pw_properties_parse_bool(val)) return 1; return 0; diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c index a21636c12..cbae203f1 100644 --- a/src/modules/module-protocol-native/local-socket.c +++ b/src/modules/module-protocol-native/local-socket.c @@ -49,12 +49,11 @@ PW_LOG_TOPIC_EXTERN(mod_topic); static const char * get_remote(const struct spa_dict *props) { - const char *name = NULL; + const char *name; - if (props) + name = getenv("PIPEWIRE_REMOTE"); + if ((name == NULL || name[0] == '\0') && props) name = spa_dict_lookup(props, PW_KEY_REMOTE_NAME); - if (name == NULL || name[0] == '\0') - name = getenv("PIPEWIRE_REMOTE"); if (name == NULL || name[0] == '\0') name = PW_DEFAULT_REMOTE; return name; diff --git a/src/modules/module-protocol-pulse/utils.c b/src/modules/module-protocol-pulse/utils.c index 617ca0524..76264493f 100644 --- a/src/modules/module-protocol-pulse/utils.c +++ b/src/modules/module-protocol-pulse/utils.c @@ -171,10 +171,9 @@ const char *get_server_name(struct pw_context *context) const char *name = NULL; const struct pw_properties *props = pw_context_get_properties(context); - if (props) + name = getenv("PIPEWIRE_REMOTE"); + if ((name == NULL || name[0] == '\0') && props != NULL) name = pw_properties_get(props, PW_KEY_REMOTE_NAME); - if (name == NULL || name[0] == '\0') - name = getenv("PIPEWIRE_REMOTE"); if (name == NULL || name[0] == '\0') name = PW_DEFAULT_REMOTE; return name; diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 6e2fba226..da49b66ca 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1899,11 +1899,12 @@ pw_stream_connect(struct pw_stream *stream, impl->disconnecting = false; stream_set_state(stream, PW_STREAM_STATE_CONNECTING, NULL); - if (target_id != PW_ID_ANY) + if ((str = getenv("PIPEWIRE_NODE")) != NULL) + pw_properties_set(stream->properties, PW_KEY_TARGET_OBJECT, str); + else if (target_id != PW_ID_ANY) /* XXX this is deprecated but still used by the portal and its apps */ pw_properties_setf(stream->properties, PW_KEY_NODE_TARGET, "%d", target_id); - else if ((str = getenv("PIPEWIRE_NODE")) != NULL) - pw_properties_set(stream->properties, PW_KEY_TARGET_OBJECT, str); + if ((flags & PW_STREAM_FLAG_AUTOCONNECT) && pw_properties_get(stream->properties, PW_KEY_NODE_AUTOCONNECT) == NULL) { str = getenv("PIPEWIRE_AUTOCONNECT");