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.
This commit is contained in:
Wim Taymans 2023-12-14 11:50:30 +01:00
parent c386c96ff0
commit 5e750f6fb8
4 changed files with 21 additions and 10 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);