From 6ab25c690483351befcb8b0613c20c26aa6e2cab Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 24 Nov 2020 15:11:05 +0100 Subject: [PATCH] pulse-server: fix parsing of format-info Fixes totem playback --- src/examples/media-session/json.h | 2 +- src/modules/module-protocol-pulse/format.c | 9 ++++++++- src/modules/module-protocol-pulse/json.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/examples/media-session/json.h b/src/examples/media-session/json.h index 6fd354818..c24bf7f6f 100644 --- a/src/examples/media-session/json.h +++ b/src/examples/media-session/json.h @@ -157,7 +157,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value) return -1; } } - return iter->depth == 0 ? 0 : -1; + return (iter->depth == 0 ? (iter->state == __BARE ? iter->cur - *value : 0) : -1); } static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type) diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index 56ccf6b1c..f61f3bd8a 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -447,7 +447,7 @@ static const struct spa_pod *format_info_build_param(struct spa_pod_builder *b, if ((len = spa_json_next(&it[0], &val)) <= 0) return NULL; if (spa_json_is_string(val, len)) { - ss.format = format_paname2id(val, len); + ss.format = format_paname2id(val+1, len-2); if (ss.format == SPA_AUDIO_FORMAT_UNKNOWN) return NULL; } else if (spa_json_is_array(val, len)) { @@ -457,6 +457,7 @@ static const struct spa_pod *format_info_build_param(struct spa_pod_builder *b, if ((str = pw_properties_get(info->props, "format.rate")) == NULL) return NULL; + spa_json_init(&it[0], str, strlen(str)); if ((len = spa_json_next(&it[0], &val)) <= 0) return NULL; @@ -473,6 +474,7 @@ static const struct spa_pod *format_info_build_param(struct spa_pod_builder *b, if ((str = pw_properties_get(info->props, "format.channels")) == NULL) return NULL; + spa_json_init(&it[0], str, strlen(str)); if ((len = spa_json_next(&it[0], &val)) <= 0) return NULL; @@ -488,6 +490,11 @@ static const struct spa_pod *format_info_build_param(struct spa_pod_builder *b, return NULL; if ((str = pw_properties_get(info->props, "format.channel_map")) != NULL) { + spa_json_init(&it[0], str, strlen(str)); + if ((len = spa_json_next(&it[0], &val)) <= 0) + return NULL; + if (!spa_json_is_string(val, len)) + return NULL; while ((*str == '\"' || *str == ',') && (len = strcspn(++str, "\",")) > 0) { map.map[map.channels++] = channel_paname2id(str, len); diff --git a/src/modules/module-protocol-pulse/json.h b/src/modules/module-protocol-pulse/json.h index 6fd354818..c24bf7f6f 100644 --- a/src/modules/module-protocol-pulse/json.h +++ b/src/modules/module-protocol-pulse/json.h @@ -157,7 +157,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value) return -1; } } - return iter->depth == 0 ? 0 : -1; + return (iter->depth == 0 ? (iter->state == __BARE ? iter->cur - *value : 0) : -1); } static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type)