diff options
author | Wim Taymans <wtaymans@redhat.com> | 2020-08-18 17:56:05 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2020-08-18 17:56:05 +0200 |
commit | 0c04481ba71ad397c5e164b5f717b3d77eb7c55f (patch) | |
tree | 3b39a7c9bd5802855df3baab58d8684ad3c618f3 | |
parent | 759e1ccb6b2f5a7c52cf3ccc329a59f093f794bd (diff) |
metadata: improve default sink/source
Only check defaults when subject is PW_ID_CORE
Handle NULL keys: remove the defaults
-rw-r--r-- | pipewire-alsa/alsa-plugins/ctl_pipewire.c | 11 | ||||
-rw-r--r-- | pipewire-jack/src/pipewire-jack.c | 16 | ||||
-rw-r--r-- | pipewire-pulseaudio/src/context.c | 18 | ||||
-rw-r--r-- | src/examples/media-session/default-nodes.c | 19 | ||||
-rw-r--r-- | src/examples/media-session/policy-node.c | 33 | ||||
-rw-r--r-- | src/tools/pw-cat.c | 15 |
6 files changed, 54 insertions, 58 deletions
diff --git a/pipewire-alsa/alsa-plugins/ctl_pipewire.c b/pipewire-alsa/alsa-plugins/ctl_pipewire.c index c20ca8e2..95aed48c 100644 --- a/pipewire-alsa/alsa-plugins/ctl_pipewire.c +++ b/pipewire-alsa/alsa-plugins/ctl_pipewire.c @@ -969,11 +969,12 @@ static int metadata_property(void *object, struct global *g = object; snd_ctl_pipewire_t *ctl = g->ctl; - if (key) { - if (strcmp(key, "default.audio.sink") == 0) - ctl->sink = value ? (uint32_t)atoi(value) : 0; - if (strcmp(key, "default.audio.source") == 0) - ctl->source = value ? (uint32_t)atoi(value) : 0; + if (subject == PW_ID_CORE) { + uint32_t val = (key && value) ? (uint32_t)atoi(value) : 0; + if (key == NULL || strcmp(key, "default.audio.sink") == 0) + ctl->sink = val; + if (key == NULL || strcmp(key, "default.audio.source") == 0) + ctl->source = val; } return 0; } diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index ed0f20f9..747bfc06 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -2004,17 +2004,11 @@ static int metadata_property(void *object, uint32_t id, pw_log_info("set id:%u key:'%s' value:'%s' type:'%s'", id, key, value, type); if (id == PW_ID_CORE) { - if (key) { - uint32_t val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - if (strcmp(key, "default.audio.sink") == 0) { - c->metadata->default_audio_sink = val; - } else if (strcmp(key, "default.audio.source") == 0) { - c->metadata->default_audio_source = val; - } - } else { - c->metadata->default_audio_source = SPA_ID_INVALID; - c->metadata->default_audio_sink = SPA_ID_INVALID; - } + uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, "default.audio.sink") == 0) + c->metadata->default_audio_sink = val; + if (key == NULL || strcmp(key, "default.audio.source") == 0) + c->metadata->default_audio_source = val; } else { o = pw_map_lookup(&c->context.globals, id); if (o == NULL) diff --git a/pipewire-pulseaudio/src/context.c b/pipewire-pulseaudio/src/context.c index 23c7124d..c4c050b1 100644 --- a/pipewire-pulseaudio/src/context.c +++ b/pipewire-pulseaudio/src/context.c @@ -1013,14 +1013,16 @@ static int metadata_property(void *object, uint32_t val; bool changed = false; - if (key && strcmp(key, METADATA_DEFAULT_SINK) == 0) { - val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - changed = c->default_sink != val; - c->default_sink = val; - } else if (key && strcmp(key, METADATA_DEFAULT_SOURCE) == 0) { - val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - changed = c->default_source != val; - c->default_source = val; + if (subject == PW_ID_CORE) { + val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, METADATA_DEFAULT_SINK) == 0) { + changed = c->default_sink != val; + c->default_sink = val; + } + if (key == NULL || strcmp(key, METADATA_DEFAULT_SOURCE) == 0) { + changed = c->default_source != val; + c->default_source = val; + } } if (changed) emit_event(global->context, global, PA_SUBSCRIPTION_EVENT_CHANGE); diff --git a/src/examples/media-session/default-nodes.c b/src/examples/media-session/default-nodes.c index df0848d0..4ef2b04a 100644 --- a/src/examples/media-session/default-nodes.c +++ b/src/examples/media-session/default-nodes.c @@ -153,26 +153,27 @@ static int metadata_property(void *object, uint32_t subject, uint32_t val; bool changed = false; - if (key == NULL) - return 0; - if (subject == PW_ID_CORE) { - val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - - if (strcmp(key, "default.audio.sink") == 0) { + val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, "default.audio.sink") == 0) { changed = val != impl->default_audio_sink; impl->default_audio_sink = val; - } else if (strcmp(key, "default.audio.source") == 0) { + } + if (key == NULL || strcmp(key, "default.audio.source") == 0) { changed = val != impl->default_audio_source; impl->default_audio_source = val; - } else if (strcmp(key, "default.video.source") == 0) { + } + if (key == NULL || strcmp(key, "default.video.source") == 0) { changed = val != impl->default_video_source; impl->default_video_source = val; } } if (changed) { const char *name = find_name_for_id(impl, val); - pw_properties_set(impl->properties, key, name); + if (key == NULL) + pw_properties_clear(impl->properties); + else + pw_properties_set(impl->properties, key, name); add_idle_timeout(impl); } return 0; diff --git a/src/examples/media-session/policy-node.c b/src/examples/media-session/policy-node.c index 4d00ba91..c9845d87 100644 --- a/src/examples/media-session/policy-node.c +++ b/src/examples/media-session/policy-node.c @@ -699,6 +699,9 @@ static int move_node(struct impl *impl, uint32_t source, uint32_t target) struct node *n, *src_node, *dst_node; const char *str; + if (source == SPA_ID_INVALID || target == SPA_ID_INVALID) + return 0; + /* find source and dest node */ if ((src_node = find_node_by_id(impl, source)) == NULL) return -ENOENT; @@ -764,30 +767,26 @@ static int metadata_property(void *object, uint32_t subject, const char *key, const char *type, const char *value) { struct impl *impl = object; - - if (key == NULL) - return 0; + uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID; if (subject == PW_ID_CORE) { - if (strcmp(key, "default.audio.sink") == 0) { - if (impl->default_audio_sink != SPA_ID_INVALID && value) - move_node(impl, impl->default_audio_sink, atoi(value)); - impl->default_audio_sink = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, "default.audio.sink") == 0) { + move_node(impl, impl->default_audio_sink, val); + impl->default_audio_sink = val; + } + if (key == NULL || strcmp(key, "default.audio.source") == 0) { + move_node(impl, impl->default_audio_source, val); + impl->default_audio_source = val; } - else if (strcmp(key, "default.audio.source") == 0) { - if (impl->default_audio_source != SPA_ID_INVALID && value) - move_node(impl, impl->default_audio_source, atoi(value)); - impl->default_audio_source = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - } else if (strcmp(key, "default.video.source") == 0) { - if (impl->default_video_source != SPA_ID_INVALID && value) - move_node(impl, impl->default_video_source, atoi(value)); - impl->default_video_source = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, "default.video.source") == 0) { + move_node(impl, impl->default_video_source, val); + impl->default_video_source = val; } } else { - if (strcmp(key, "target.node") == 0 && value != NULL) { + if (val != SPA_ID_INVALID && strcmp(key, "target.node") == 0) { struct node *src_node, *dst_node; - dst_node = find_node_by_id(impl, atoi(value)); + dst_node = find_node_by_id(impl, val); src_node = dst_node ? find_node_by_id(impl, subject) : NULL; if (dst_node && src_node) diff --git a/src/tools/pw-cat.c b/src/tools/pw-cat.c index 8549bcf4..9619d245 100644 --- a/src/tools/pw-cat.c +++ b/src/tools/pw-cat.c @@ -649,14 +649,13 @@ static int metadata_property(void *object, uint32_t subject, const char *key, const char *type, const char *value) { struct data *data = object; - uint32_t val; - - if (key && strcmp(key, "default.audio.sink") == 0) { - val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - data->default_sink = val; - } else if (key && strcmp(key, "default.audio.source") == 0) { - val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID; - data->default_source = val; + + if (subject == PW_ID_CORE) { + uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID; + if (key == NULL || strcmp(key, "default.audio.sink") == 0) + data->default_sink = val; + if (key == NULL || strcmp(key, "default.audio.source") == 0) + data->default_source = val; } return 0; } |