From 00a82017a29370ac07cc973bc66cf2faf4f7d3c9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 8 Sep 2023 12:19:05 +0200 Subject: [PATCH] stream: fix datatyp on copied object First copy the object and then modify it to avoid changing the user provided param. --- src/pipewire/filter.c | 14 +++++++------- src/pipewire/stream.c | 14 +++++++------- src/pipewire/stream.h | 4 +--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index dd1475682..60d912383 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -197,10 +197,10 @@ static int get_port_param_index(uint32_t id) } } -static void fix_datatype(const struct spa_pod *param) +static void fix_datatype(struct spa_pod *param) { const struct spa_pod_prop *pod_param; - const struct spa_pod *vals; + struct spa_pod *vals; uint32_t dataType, n_vals, choice; pod_param = spa_pod_find_prop(param, NULL, SPA_PARAM_BUFFERS_dataType); @@ -240,11 +240,6 @@ static struct param *add_param(struct filter *impl, struct port *port, if (p == NULL) return NULL; - if (id == SPA_PARAM_Buffers && port != NULL && - SPA_FLAG_IS_SET(port->flags, PW_FILTER_PORT_FLAG_MAP_BUFFERS) && - port->direction == SPA_DIRECTION_INPUT) - fix_datatype(param); - if (id == SPA_PARAM_ProcessLatency && port == NULL) spa_process_latency_parse(param, &impl->process_latency); @@ -254,6 +249,11 @@ static struct param *add_param(struct filter *impl, struct port *port, memcpy(p->param, param, SPA_POD_SIZE(param)); SPA_POD_OBJECT_ID(p->param) = id; + if (id == SPA_PARAM_Buffers && port != NULL && + SPA_FLAG_IS_SET(port->flags, PW_FILTER_PORT_FLAG_MAP_BUFFERS) && + port->direction == SPA_DIRECTION_INPUT) + fix_datatype(p->param); + pw_log_debug("%p: port %p param id %d (%s)", impl, p, id, spa_debug_type_find_name(spa_type_param, id)); diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index d5604485d..d84120b46 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -199,10 +199,10 @@ static int get_port_param_index(uint32_t id) } } -static void fix_datatype(const struct spa_pod *param) +static void fix_datatype(struct spa_pod *param) { const struct spa_pod_prop *pod_param; - const struct spa_pod *vals; + struct spa_pod *vals; uint32_t dataType, n_vals, choice; pod_param = spa_pod_find_prop(param, NULL, SPA_PARAM_BUFFERS_dataType); @@ -242,17 +242,17 @@ static struct param *add_param(struct stream *impl, if (p == NULL) return NULL; - if (id == SPA_PARAM_Buffers && - SPA_FLAG_IS_SET(impl->flags, PW_STREAM_FLAG_MAP_BUFFERS) && - impl->direction == SPA_DIRECTION_INPUT) - fix_datatype(param); - p->id = id; p->flags = flags; p->param = SPA_PTROFF(p, sizeof(struct param), struct spa_pod); memcpy(p->param, param, SPA_POD_SIZE(param)); SPA_POD_OBJECT_ID(p->param) = id; + if (id == SPA_PARAM_Buffers && + SPA_FLAG_IS_SET(impl->flags, PW_STREAM_FLAG_MAP_BUFFERS) && + impl->direction == SPA_DIRECTION_INPUT) + fix_datatype(p->param); + spa_list_append(&impl->param_list, &p->link); if ((idx = get_param_index(id)) != -1) { diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index 31793fa91..f2777bec0 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -469,9 +469,7 @@ int pw_stream_set_error(struct pw_stream *stream, /**< a \ref pw_stream */ /** Update the param exposed on the stream. */ int pw_stream_update_params(struct pw_stream *stream, /**< a \ref pw_stream */ - const struct spa_pod **params, /**< an array of params. The params should - * ideally contain parameters for doing - * buffer allocation. */ + const struct spa_pod **params, /**< an array of params. */ uint32_t n_params /**< number of elements in \a params */); /**