pulse-server: use args_to_audioinfo to parse channels

This commit is contained in:
Wim Taymans 2021-04-19 16:49:25 +02:00
parent 649d21ac02
commit 575163e644

View file

@ -128,8 +128,8 @@ struct module *create_module_null_sink(struct impl *impl, const char *argument)
struct module_null_sink_data *d; struct module_null_sink_data *d;
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
const char *str; const char *str;
struct channel_map map = CHANNEL_MAP_INIT; struct spa_audio_info_raw info = { 0 };
uint32_t i, channels; uint32_t i;
int res; int res;
props = pw_properties_new_dict(&SPA_DICT_INIT_ARRAY(module_null_sink_info)); props = pw_properties_new_dict(&SPA_DICT_INIT_ARRAY(module_null_sink_info));
@ -150,42 +150,23 @@ struct module *create_module_null_sink(struct impl *impl, const char *argument)
module_args_add_props(props, str); module_args_add_props(props, str);
pw_properties_set(props, "sink_properties", NULL); pw_properties_set(props, "sink_properties", NULL);
} }
if ((str = pw_properties_get(props, "channels")) != NULL) {
channels = atoi(str); if (module_args_to_audioinfo(impl, props, &info) < 0) {
pw_properties_set(props, SPA_KEY_AUDIO_CHANNELS, str);
pw_properties_set(props, "channels", NULL);
} else {
channels = impl->defs.sample_spec.channels;
pw_properties_setf(props, SPA_KEY_AUDIO_CHANNELS, "%u", channels);
}
if ((str = pw_properties_get(props, "rate")) != NULL) {
pw_properties_set(props, SPA_KEY_AUDIO_RATE, str);
pw_properties_set(props, "rate", NULL);
}
if ((str = pw_properties_get(props, "channel_map")) != NULL) {
channel_map_parse(str, &map);
pw_properties_set(props, "channel_map", NULL);
} else {
if (channels == impl->defs.channel_map.channels) {
map = impl->defs.channel_map;
} else {
for (i = 0; i < channels; i++)
map.map[i] = SPA_AUDIO_CHANNEL_UNKNOWN;
map.channels = channels;
}
}
if (map.channels != channels) {
pw_log_error("channel map does not match channels");
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (map.channels > 0) { if (info.rate)
pw_properties_setf(props, SPA_KEY_AUDIO_RATE, "%u", info.rate);
if (info.channels) {
char *s, *p; char *s, *p;
p = s = alloca(map.channels * 6);
for (i = 0; i < map.channels; i++) pw_properties_setf(props, SPA_KEY_AUDIO_CHANNELS, "%u", info.channels);
p = s = alloca(info.channels * 6);
for (i = 0; i < info.channels; i++)
p += snprintf(p, 6, "%s%s", i == 0 ? "" : ",", p += snprintf(p, 6, "%s%s", i == 0 ? "" : ",",
channel_id2name(map.map[i])); channel_id2name(info.position[i]));
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }