From 283c21564186ee7d5dfc3dec28f355c8112b1d45 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 11 Dec 2023 13:01:10 +0100 Subject: [PATCH] stream: make empty objects remove the PARAM Make sure that NULL params don't cause -EINVAL but ignore them. Don't add empty param objects. this makes it possible to clear all previous params by setting an empty object. --- spa/include/spa/pod/iter.h | 8 ++++++++ src/pipewire/filter.c | 22 ++++++++++------------ src/pipewire/stream.c | 19 +++++++++---------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/spa/include/spa/pod/iter.h b/spa/include/spa/pod/iter.h index 05abfc1c9..8e97130f8 100644 --- a/spa/include/spa/pod/iter.h +++ b/spa/include/spa/pod/iter.h @@ -437,6 +437,14 @@ static inline int spa_pod_object_is_fixated(const struct spa_pod_object *pod) return 1; } +static inline int spa_pod_object_has_props(const struct spa_pod_object *pod) +{ + struct spa_pod_prop *res; + SPA_POD_OBJECT_FOREACH(pod, res) + return 1; + return 0; +} + static inline int spa_pod_is_fixated(const struct spa_pod *pod) { if (!spa_pod_is_object(pod)) diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index 6dbf050ea..7412aedd4 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -224,22 +224,23 @@ static void fix_datatype(struct spa_pod *param) } } -static struct param *add_param(struct filter *impl, struct port *port, +static int add_param(struct filter *impl, struct port *port, uint32_t id, uint32_t flags, const struct spa_pod *param) { struct param *p; int idx; - if (param == NULL || !spa_pod_is_object(param)) { - errno = EINVAL; - return NULL; - } + if (param != NULL && !spa_pod_is_object(param)) + return -EINVAL; + if (param == NULL || !spa_pod_object_has_props((struct spa_pod_object*)param)) + return 0; + if (id == SPA_ID_INVALID) id = SPA_POD_OBJECT_ID(param); p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); if (p == NULL) - return NULL; + return -errno; if (id == SPA_PARAM_ProcessLatency && port == NULL) spa_process_latency_parse(param, &impl->process_latency); @@ -275,7 +276,7 @@ static struct param *add_param(struct filter *impl, struct port *port, impl->params[idx].user++; } } - return p; + return 0; } static void clear_params(struct filter *impl, struct port *port, uint32_t id) @@ -702,10 +703,8 @@ static int update_params(struct filter *impl, struct port *port, uint32_t id, } continue; } - if (add_param(impl, port, id, 0, params[i]) == NULL) { - res = -errno; + if ((res = add_param(impl, port, id, 0, params[i])) < 0) break; - } } if (port != NULL && update_latency) { uint8_t buffer[4096]; @@ -1636,9 +1635,8 @@ pw_filter_connect(struct pw_filter *filter, impl->info.change_mask = impl->change_mask_all; clear_params(impl, NULL, SPA_ID_INVALID); - for (i = 0; i < n_params; i++) { + for (i = 0; i < n_params; i++) add_param(impl, NULL, SPA_ID_INVALID, 0, params[i]); - } impl->disconnecting = false; impl->draining = false; diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index d9fae3330..ee35c4f0a 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -226,22 +226,23 @@ static void fix_datatype(struct spa_pod *param) } } -static struct param *add_param(struct stream *impl, +static int add_param(struct stream *impl, uint32_t id, uint32_t flags, const struct spa_pod *param) { struct param *p; int idx; - if (param == NULL || !spa_pod_is_object(param)) { - errno = EINVAL; - return NULL; - } + if (param != NULL && !spa_pod_is_object(param)) + return -EINVAL; + if (param == NULL || !spa_pod_object_has_props((struct spa_pod_object*)param)) + return 0; + if (id == SPA_ID_INVALID) id = SPA_POD_OBJECT_ID(param); p = malloc(sizeof(struct param) + SPA_POD_SIZE(param)); if (p == NULL) - return NULL; + return -errno; p->id = id; p->flags = flags; @@ -266,7 +267,7 @@ static struct param *add_param(struct stream *impl, impl->port_params[idx].flags |= SPA_PARAM_INFO_READ; impl->port_params[idx].user++; } - return p; + return 0; } static void clear_params(struct stream *impl, uint32_t id) @@ -326,10 +327,8 @@ static int update_params(struct stream *impl, uint32_t id, } } for (i = 0; i < n_params; i++) { - if (add_param(impl, id, 0, params[i]) == NULL) { - res = -errno; + if ((res = add_param(impl, id, 0, params[i])) < 0) break; - } } return res; }