From 61d318125e894bb1dbf389b4ae6705b6a2899e14 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 22 Apr 2022 09:37:21 +0200 Subject: [PATCH] move PIPEWIRE_PROPS to stream and filter Make all streams and filters handle PIPEWIRE_PROPS. The order for applying stream/filter properties is: 1) application provided properties. 2) generic config. 3) match rules. 4) environment variables (PIPEWIRE_PROPS, ...) from generic to more specific. 5) defaults. --- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 7 +--- pipewire-jack/src/pipewire-jack.c | 14 ++++---- pipewire-v4l2/src/pipewire-v4l2.c | 8 ++--- src/pipewire/filter.c | 37 +++++++++++---------- src/pipewire/stream.c | 39 ++++++++++++----------- 5 files changed, 51 insertions(+), 54 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index e9cfef587..600f68ef0 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -473,7 +473,6 @@ static int snd_pcm_pipewire_prepare(snd_pcm_ioplug_t *io) snd_pcm_pipewire_t *pw = io->private_data; snd_pcm_sw_params_t *swparams; const struct spa_pod *params[1]; - const char *str; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); struct pw_properties *props; @@ -504,11 +503,7 @@ static int snd_pcm_pipewire_prepare(snd_pcm_ioplug_t *io) pw->stream = NULL; } - props = NULL; - if ((str = getenv("PIPEWIRE_PROPS")) != NULL) - props = pw_properties_new_string(str); - if (props == NULL) - props = pw_properties_new(NULL, NULL); + props = pw_properties_new(NULL, NULL); if (props == NULL) goto error; diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 3b1724335..966cc9937 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3228,9 +3228,6 @@ jack_client_t * jack_client_open (const char *client_name, pw_context_conf_update_props(client->context.context, "jack.properties", client->props); - if ((str = getenv("PIPEWIRE_PROPS")) != NULL) - pw_properties_update_string(client->props, str, strlen(str)); - pw_context_conf_section_match_rules(client->context.context, "jack.rules", &client->props->dict, execute_match, client); @@ -3321,10 +3318,8 @@ jack_client_t * jack_client_open (const char *client_name, &client->registry_listener, ®istry_events, client); - if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) - pw_properties_set(client->props, PW_KEY_NODE_LATENCY, str); - if ((str = getenv("PIPEWIRE_RATE")) != NULL) - pw_properties_set(client->props, PW_KEY_NODE_RATE, str); + if ((str = getenv("PIPEWIRE_PROPS")) != NULL) + pw_properties_update_string(client->props, str, strlen(str)); if ((str = getenv("PIPEWIRE_QUANTUM")) != NULL) { struct spa_fraction q; if (sscanf(str, "%u/%u", &q.num, &q.denom) == 2 && q.denom != 0) { @@ -3336,6 +3331,11 @@ jack_client_t * jack_client_open (const char *client_name, pw_log_warn("invalid PIPEWIRE_QUANTUM: %s", str); } } + if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) + pw_properties_set(client->props, PW_KEY_NODE_LATENCY, str); + if ((str = getenv("PIPEWIRE_RATE")) != NULL) + pw_properties_set(client->props, PW_KEY_NODE_RATE, str); + if ((str = pw_properties_get(client->props, PW_KEY_NODE_LATENCY)) != NULL) { uint32_t num, denom; if (sscanf(str, "%u/%u", &num, &denom) == 2 && denom != 0) { diff --git a/pipewire-v4l2/src/pipewire-v4l2.c b/pipewire-v4l2/src/pipewire-v4l2.c index 544c4a6b1..47e1721c2 100644 --- a/pipewire-v4l2/src/pipewire-v4l2.c +++ b/pipewire-v4l2/src/pipewire-v4l2.c @@ -1426,7 +1426,6 @@ static int connect_stream(struct file *file) { int res; struct global *g = file->node; - const char *str; struct timespec abstime; const char *error = NULL; uint8_t buffer[1024]; @@ -1442,11 +1441,7 @@ static int connect_stream(struct file *file) disconnect_stream(file); - props = NULL; - if ((str = getenv("PIPEWIRE_PROPS")) != NULL) - props = pw_properties_new_string(str); - if (props == NULL) - props = pw_properties_new(NULL, NULL); + props = pw_properties_new(NULL, NULL); if (props == NULL) { res = -errno; goto exit; @@ -1470,6 +1465,7 @@ static int connect_stream(struct file *file) &file->stream_listener, &stream_events, file); + file->error = 0; pw_stream_connect(file->stream, diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index d01b0b1f5..95a6a837c 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1211,20 +1211,16 @@ filter_new(struct pw_context *context, const char *name, res = -errno; goto error_properties; } + spa_hook_list_init(&impl->hooks); + this->properties = props; + pw_context_conf_update_props(context, "filter.properties", props); - if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL && extra) { - str = pw_properties_get(extra, PW_KEY_APP_NAME); - if (str == NULL) - str = pw_properties_get(extra, PW_KEY_APP_PROCESS_BINARY); - if (str == NULL) - str = name; - pw_properties_set(props, PW_KEY_NODE_NAME, str); - } - if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) - pw_properties_set(props, PW_KEY_NODE_LATENCY, str); - if ((str = getenv("PIPEWIRE_RATE")) != NULL) - pw_properties_set(props, PW_KEY_NODE_RATE, str); + pw_context_conf_section_match_rules(impl->context, "filter.rules", + &this->properties->dict, execute_match, this); + + if ((str = getenv("PIPEWIRE_PROPS")) != NULL) + pw_properties_update_string(props, str, strlen(str)); if ((str = getenv("PIPEWIRE_QUANTUM")) != NULL) { struct spa_fraction q; if (sscanf(str, "%u/%u", &q.num, &q.denom) == 2 && q.denom != 0) { @@ -1234,12 +1230,19 @@ filter_new(struct pw_context *context, const char *name, "%u/%u", q.num, q.denom); } } + if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) + pw_properties_set(props, PW_KEY_NODE_LATENCY, str); + if ((str = getenv("PIPEWIRE_RATE")) != NULL) + pw_properties_set(props, PW_KEY_NODE_RATE, str); - spa_hook_list_init(&impl->hooks); - this->properties = props; - - pw_context_conf_section_match_rules(impl->context, "filter.rules", - &this->properties->dict, execute_match, this); + if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL && extra) { + str = pw_properties_get(extra, PW_KEY_APP_NAME); + if (str == NULL) + str = pw_properties_get(extra, PW_KEY_APP_PROCESS_BINARY); + if (str == NULL) + str = name; + pw_properties_set(props, PW_KEY_NODE_NAME, str); + } this->name = name ? strdup(name) : NULL; this->node_id = SPA_ID_INVALID; diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index a572eb009..237e55dc2 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1411,23 +1411,16 @@ stream_new(struct pw_context *context, const char *name, res = -errno; goto error_properties; } + spa_hook_list_init(&impl->hooks); + this->properties = props; + pw_context_conf_update_props(context, "stream.properties", props); - if (pw_properties_get(props, PW_KEY_STREAM_IS_LIVE) == NULL) - pw_properties_set(props, PW_KEY_STREAM_IS_LIVE, "true"); + pw_context_conf_section_match_rules(context, "stream.rules", + &this->properties->dict, execute_match, this); - if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL && extra) { - str = pw_properties_get(extra, PW_KEY_APP_NAME); - if (str == NULL) - str = pw_properties_get(extra, PW_KEY_APP_PROCESS_BINARY); - if (str == NULL) - str = name; - pw_properties_set(props, PW_KEY_NODE_NAME, str); - } - if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) - pw_properties_set(props, PW_KEY_NODE_LATENCY, str); - if ((str = getenv("PIPEWIRE_RATE")) != NULL) - pw_properties_set(props, PW_KEY_NODE_RATE, str); + if ((str = getenv("PIPEWIRE_PROPS")) != NULL) + pw_properties_update_string(props, str, strlen(str)); if ((str = getenv("PIPEWIRE_QUANTUM")) != NULL) { struct spa_fraction q; if (sscanf(str, "%u/%u", &q.num, &q.denom) == 2 && q.denom != 0) { @@ -1437,11 +1430,21 @@ stream_new(struct pw_context *context, const char *name, "%u/%u", q.num, q.denom); } } - spa_hook_list_init(&impl->hooks); - this->properties = props; + if ((str = getenv("PIPEWIRE_LATENCY")) != NULL) + pw_properties_set(props, PW_KEY_NODE_LATENCY, str); + if ((str = getenv("PIPEWIRE_RATE")) != NULL) + pw_properties_set(props, PW_KEY_NODE_RATE, str); - pw_context_conf_section_match_rules(context, "stream.rules", - &this->properties->dict, execute_match, this); + if (pw_properties_get(props, PW_KEY_STREAM_IS_LIVE) == NULL) + pw_properties_set(props, PW_KEY_STREAM_IS_LIVE, "true"); + if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL && extra) { + str = pw_properties_get(extra, PW_KEY_APP_NAME); + if (str == NULL) + str = pw_properties_get(extra, PW_KEY_APP_PROCESS_BINARY); + if (str == NULL) + str = name; + pw_properties_set(props, PW_KEY_NODE_NAME, str); + } this->name = name ? strdup(name) : NULL; this->node_id = SPA_ID_INVALID;