diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index e2a7696d4..3477ea01c 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -390,6 +390,22 @@ void channel_map_parse(const char *str, struct channel_map *map) } } +void channel_map_parse_position(const char *str, struct channel_map *map) +{ + struct spa_json it[2]; + char v[256]; + + spa_json_init(&it[0], str, strlen(str)); + if (spa_json_enter_array(&it[0], &it[1]) <= 0) + spa_json_init(&it[1], str, strlen(str)); + + map->channels = 0; + while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && + map->channels < SPA_AUDIO_MAX_CHANNELS) { + map->map[map->channels++] = channel_name2id(v); + } +} + bool channel_map_valid(const struct channel_map *map) { uint8_t i; diff --git a/src/modules/module-protocol-pulse/format.h b/src/modules/module-protocol-pulse/format.h index 7fddfdd4e..77795a5e4 100644 --- a/src/modules/module-protocol-pulse/format.h +++ b/src/modules/module-protocol-pulse/format.h @@ -187,6 +187,7 @@ uint32_t channel_paname2id(const char *name, size_t size); void channel_map_to_positions(const struct channel_map *map, uint32_t *pos); void channel_map_parse(const char *str, struct channel_map *map); bool channel_map_valid(const struct channel_map *map); +void channel_map_parse_position(const char *str, struct channel_map *map); int format_parse_param(const struct spa_pod *param, bool collect, struct sample_spec *ss, struct channel_map *map, const struct sample_spec *def_ss, diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 0beda77a3..fbfe7a6f1 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -5471,22 +5471,13 @@ static int parse_position(struct pw_properties *props, const char *key, const ch struct channel_map *res) { const char *str; - struct spa_json it[2]; - char v[256]; if (props == NULL || (str = pw_properties_get(props, key)) == NULL) str = def; - spa_json_init(&it[0], str, strlen(str)); - if (spa_json_enter_array(&it[0], &it[1]) <= 0) - spa_json_init(&it[1], str, strlen(str)); + channel_map_parse_position(str, res); - res->channels = 0; - while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && - res->channels < SPA_AUDIO_MAX_CHANNELS) { - res->map[res->channels++] = channel_name2id(v); - } pw_log_info(": defaults: %s = %s", key, str); return 0; }