pulse-server: refactor channel position parsing

This commit is contained in:
Wim Taymans 2023-02-23 12:39:36 +01:00
parent eca4049a38
commit ad6ab7e0b7
3 changed files with 18 additions and 10 deletions

View file

@ -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) bool channel_map_valid(const struct channel_map *map)
{ {
uint8_t i; uint8_t i;

View file

@ -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_to_positions(const struct channel_map *map, uint32_t *pos);
void channel_map_parse(const char *str, struct channel_map *map); void channel_map_parse(const char *str, struct channel_map *map);
bool channel_map_valid(const 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, 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, struct channel_map *map, const struct sample_spec *def_ss,

View file

@ -5471,22 +5471,13 @@ static int parse_position(struct pw_properties *props, const char *key, const ch
struct channel_map *res) struct channel_map *res)
{ {
const char *str; const char *str;
struct spa_json it[2];
char v[256];
if (props == NULL || if (props == NULL ||
(str = pw_properties_get(props, key)) == NULL) (str = pw_properties_get(props, key)) == NULL)
str = def; str = def;
spa_json_init(&it[0], str, strlen(str)); channel_map_parse_position(str, res);
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
spa_json_init(&it[1], str, strlen(str));
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); pw_log_info(": defaults: %s = %s", key, str);
return 0; return 0;
} }