From 47298b8de8c86424bd9b664568c18f8e88cf559d Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 12 Jan 2022 13:22:31 -0500 Subject: [PATCH] sink, source: Add a way to change channel map This adds functions to allow changing the channel map on a sink or source. We make module-null-sink use this function instead of changing the channel map manually to allow for logging and notifications. The source function is currently unused but we add it to maintain symmetry with the sink. --- src/modules/module-null-sink.c | 9 ++++++--- src/pulsecore/sink.c | 23 +++++++++++++++++++++++ src/pulsecore/sink.h | 1 + src/pulsecore/source.c | 23 +++++++++++++++++++++++ src/pulsecore/source.h | 1 + 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 183c9d8d8..4afbd26df 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -182,9 +182,12 @@ static int sink_reconfigure_cb(pa_sink *s, pa_sample_spec *spec, pa_channel_map s->sample_spec = *spec; if (map) - s->channel_map = *map; - else - pa_channel_map_init_auto(&s->channel_map, spec->channels, PA_CHANNEL_MAP_DEFAULT); + pa_sink_set_channel_map(s, map); + else { + pa_channel_map def_map; + pa_channel_map_init_auto(&def_map, spec->channels, PA_CHANNEL_MAP_DEFAULT); + pa_sink_set_channel_map(s, &def_map); + } return 0; } diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 9231cf9d6..43a12f390 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -4083,6 +4083,29 @@ void pa_sink_set_sample_rate(pa_sink *s, uint32_t rate) { pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } +/* Called from the main thread */ +void pa_sink_set_channel_map(pa_sink *s, pa_channel_map *map) { + pa_channel_map old_map; + char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX]; + char new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX]; + + pa_assert(s); + pa_assert(map); + pa_assert(pa_channel_map_valid(map)); + + old_map = s->channel_map; + if (pa_channel_map_equal(&old_map, map)) + return; + + pa_log_info("%s: channel map: %s -> %s", s->name, + pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map), + pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map)); + + s->channel_map = *map; + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from the main thread. */ void pa_sink_set_reference_volume_direct(pa_sink *s, const pa_cvolume *volume) { pa_cvolume old_volume; diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index e83477761..764721a55 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -529,6 +529,7 @@ pa_idxset* pa_sink_check_formats(pa_sink *s, pa_idxset *in_formats); void pa_sink_set_sample_format(pa_sink *s, pa_sample_format_t format); void pa_sink_set_sample_rate(pa_sink *s, uint32_t rate); +void pa_sink_set_channel_map(pa_sink *s, pa_channel_map *map); /*** To be called exclusively by the sink driver, from IO context */ diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 2e62a8593..d3ed57254 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -3077,6 +3077,29 @@ void pa_source_set_sample_rate(pa_source *s, uint32_t rate) { pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } +/* Called from the main thread */ +void pa_source_set_channel_map(pa_source *s, pa_channel_map *map) { + pa_channel_map old_map; + char old_map_str[PA_CHANNEL_MAP_SNPRINT_MAX]; + char new_map_str[PA_CHANNEL_MAP_SNPRINT_MAX]; + + pa_assert(s); + pa_assert(map); + pa_assert(pa_channel_map_valid(map)); + + old_map = s->channel_map; + if (pa_channel_map_equal(&old_map, map)) + return; + + pa_log_info("%s: channel map: %s -> %s", s->name, + pa_channel_map_snprint(old_map_str, sizeof(old_map_str), &old_map), + pa_channel_map_snprint(new_map_str, sizeof(new_map_str), map)); + + s->channel_map = *map; + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from the main thread. */ void pa_source_set_reference_volume_direct(pa_source *s, const pa_cvolume *volume) { pa_cvolume old_volume; diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h index daaa4c6d8..64ea11f9d 100644 --- a/src/pulsecore/source.h +++ b/src/pulsecore/source.h @@ -450,6 +450,7 @@ pa_idxset* pa_source_check_formats(pa_source *s, pa_idxset *in_formats); void pa_source_set_sample_format(pa_source *s, pa_sample_format_t format); void pa_source_set_sample_rate(pa_source *s, uint32_t rate); +void pa_source_set_channel_map(pa_source *s, pa_channel_map *map); /*** To be called exclusively by the source driver, from IO context */