From 8bf7ce5fa49f01c6db142360d35338832c902eb4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 14 Apr 2021 15:23:34 +0200 Subject: [PATCH] pulse-server: fix channels property Setting the channel property should create as many channels as requested, not just the number from the default channel map. If no channel_map is set, use the default one if the channels match or use one with unknown channel layout otherwise. Check the configured channels against the channel map and error if there is a mismatch. --- .../module-protocol-pulse/module-null-sink.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/modules/module-protocol-pulse/module-null-sink.c b/src/modules/module-protocol-pulse/module-null-sink.c index 403367218..312b50a96 100644 --- a/src/modules/module-protocol-pulse/module-null-sink.c +++ b/src/modules/module-protocol-pulse/module-null-sink.c @@ -123,6 +123,7 @@ static struct module *create_module_null_sink(struct impl *impl, const char *arg struct pw_properties *props = NULL; const char *str; struct channel_map map = CHANNEL_MAP_INIT; + uint32_t i, channels; int res; props = pw_properties_new_dict(&SPA_DICT_INIT_ARRAY(module_null_sink_info)); @@ -144,11 +145,12 @@ static struct module *create_module_null_sink(struct impl *impl, const char *arg pw_properties_set(props, "sink_properties", NULL); } if ((str = pw_properties_get(props, "channels")) != NULL) { + channels = atoi(str); pw_properties_set(props, SPA_KEY_AUDIO_CHANNELS, str); pw_properties_set(props, "channels", NULL); } else { - pw_properties_setf(props, SPA_KEY_AUDIO_CHANNELS, "%u", - impl->defs.sample_spec.channels); + 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); @@ -158,10 +160,21 @@ static struct module *create_module_null_sink(struct impl *impl, const char *arg channel_map_parse(str, &map); pw_properties_set(props, "channel_map", NULL); } else { - map = impl->defs.channel_map; + 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; + goto out; + } + if (map.channels > 0) { - uint32_t i; char *s, *p; p = s = alloca(map.channels * 6); for (i = 0; i < map.channels; i++)