From 5e750f6fb8b79e1e7e5819bb09a663e268556c4a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Dec 2023 11:50:30 +0100 Subject: [PATCH] modules: place floats in properties in JSON format Using %f will result in a locale dependent format and might not parse with JSON parsers or even our own spa_atof() function. --- .../modules/module-echo-cancel.c | 12 ++++++++++-- src/modules/module-rtp-sap.c | 4 ++-- src/modules/module-rtp/stream.c | 9 +++++---- src/modules/module-vban/stream.c | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/modules/module-protocol-pulse/modules/module-echo-cancel.c b/src/modules/module-protocol-pulse/modules/module-echo-cancel.c index 9737266db..3e471811c 100644 --- a/src/modules/module-protocol-pulse/modules/module-echo-cancel.c +++ b/src/modules/module-protocol-pulse/modules/module-echo-cancel.c @@ -192,10 +192,14 @@ static int rename_geometry(struct pw_properties *props, const char *pa_key, cons fprintf(f, "[ "); while (true) { float p[3]; + char ps0[64], ps1[64], ps2[64]; if ((len = parse_point(&str, p)) < 0) break; - fprintf(f, "[ %f %f %f ] ", p[0], p[1], p[2]); + fprintf(f, "[ %s %s %s ] ", + spa_dtoa(ps0, sizeof(ps0), p[0]), + spa_dtoa(ps1, sizeof(ps1), p[1]), + spa_dtoa(ps2, sizeof(ps2), p[2])); str += len; if (*str != ',') break; @@ -216,6 +220,7 @@ static int rename_direction(struct pw_properties *props, const char *pa_key, con const char *str; int res; float f[3]; + char fs0[64], fs1[64], fs2[64]; if ((str = pw_properties_get(props, pa_key)) == NULL) return 0; @@ -225,7 +230,10 @@ static int rename_direction(struct pw_properties *props, const char *pa_key, con if ((res = parse_point(&str, f)) < 0) return res; - pw_properties_setf(props, pw_key, "[ %f %f %f ]", f[0], f[1], f[2]); + pw_properties_setf(props, pw_key, "[ %s %s %s ]", + spa_dtoa(fs0, sizeof(fs0), f[0]), + spa_dtoa(fs1, sizeof(fs1), f[1]), + spa_dtoa(fs2, sizeof(fs2), f[2])); pw_properties_set(props, pa_key, NULL); return 0; } diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index 839c131ac..133539af8 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -868,7 +868,7 @@ static struct session *session_new(struct impl *impl, struct sdp_info *info) struct session *session; struct pw_properties *props; const char *str; - char dst_addr[64]; + char dst_addr[64], tmp[64]; if (impl->n_sessions >= MAX_SESSIONS) { pw_log_warn("too many sessions (%u >= %u)", impl->n_sessions, MAX_SESSIONS); @@ -908,7 +908,7 @@ static struct session *session_new(struct impl *impl, struct sdp_info *info) pw_properties_setf(props, "rtp.destination.ip", "%s", dst_addr); pw_properties_setf(props, "rtp.destination.port", "%u", info->dst_port); pw_properties_setf(props, "rtp.payload", "%u", info->payload); - pw_properties_setf(props, "rtp.ptime", "%f", info->ptime); + pw_properties_set(props, "rtp.ptime", spa_dtoa(tmp, sizeof(tmp), info->ptime)); pw_properties_setf(props, "rtp.media", "%s", info->media_type); pw_properties_setf(props, "rtp.mime", "%s", info->mime_type); pw_properties_setf(props, "rtp.rate", "%u", info->rate); diff --git a/src/modules/module-rtp/stream.c b/src/modules/module-rtp/stream.c index 1893f79b7..3c12bae52 100644 --- a/src/modules/module-rtp/stream.c +++ b/src/modules/module-rtp/stream.c @@ -272,6 +272,7 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core, { struct impl *impl; const char *str; + char tmp[64]; uint8_t buffer[1024]; struct spa_pod_builder b; uint32_t n_params, min_samples, max_samples; @@ -421,8 +422,9 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core, impl->psamples = impl->mtu / impl->stride; impl->psamples = SPA_CLAMP(impl->psamples, min_samples, max_samples); if (direction == PW_DIRECTION_INPUT) - pw_properties_setf(props, "rtp.ptime", "%f", - impl->psamples * 1000.0 / impl->rate); + pw_properties_set(props, "rtp.ptime", + spa_dtoa(tmp, sizeof(tmp), + impl->psamples * 1000.0 / impl->rate)); } latency_msec = pw_properties_get_uint32(props, "sess.latency.msec", DEFAULT_SESS_LATENCY); @@ -583,6 +585,5 @@ int rtp_stream_update_params(struct rtp_stream *s, uint32_t n_params) { struct impl *impl = (struct impl*)s; - return pw_stream_update_params(impl->stream, params, n_params); -} \ No newline at end of file +} diff --git a/src/modules/module-vban/stream.c b/src/modules/module-vban/stream.c index 8f1f19ff3..eb005cbbc 100644 --- a/src/modules/module-vban/stream.c +++ b/src/modules/module-vban/stream.c @@ -253,6 +253,7 @@ struct vban_stream *vban_stream_new(struct pw_core *core, { struct impl *impl; const char *str; + char tmp[64]; uint8_t buffer[1024]; struct spa_pod_builder b; uint32_t n_params, min_samples, max_samples; @@ -370,8 +371,9 @@ struct vban_stream *vban_stream_new(struct pw_core *core, impl->psamples = impl->mtu / impl->stride; impl->psamples = SPA_CLAMP(impl->psamples, min_samples, max_samples); if (direction == PW_DIRECTION_OUTPUT) - pw_properties_setf(props, "vban.ptime", "%f", - impl->psamples * 1000.0 / impl->rate); + pw_properties_set(props, "vban.ptime", + spa_dtoa(tmp, sizeof(tmp), + impl->psamples * 1000.0 / impl->rate)); } latency_msec = pw_properties_get_uint32(props, "sess.latency.msec", DEFAULT_SESS_LATENCY);