From 4693028b9b706616b43d058e3b165d13090b1aff Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 12 Jan 2022 13:22:34 -0500 Subject: [PATCH] sink, source: Add API to change channel count This makes this part symmetrical with the rest of the sample spec, and will be useful when we implement switching channel count in a sink. --- src/pulsecore/sink.c | 18 ++++++++++++++++++ src/pulsecore/sink.h | 1 + src/pulsecore/source.c | 18 ++++++++++++++++++ src/pulsecore/source.h | 1 + 4 files changed, 38 insertions(+) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 43a12f390..f6d15b9e3 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -4083,6 +4083,24 @@ 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_channels(pa_sink *s, uint8_t channels) { + uint8_t old_channels; + + pa_assert(s); + pa_assert(pa_channels_valid(channels)); + + old_channels = s->sample_spec.channels; + if (old_channels == channels) + return; + + pa_log_info("%s: channels: %u -> %u", s->name, old_channels, channels); + + s->sample_spec.channels = channels; + + 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; diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index 764721a55..9ff68c877 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_channels(pa_sink *s, uint8_t channels); 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 d3ed57254..58e4e458a 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -3077,6 +3077,24 @@ 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_channels(pa_source *s, uint8_t channels) { + uint8_t old_channels; + + pa_assert(s); + pa_assert(pa_channels_valid(channels)); + + old_channels = s->sample_spec.channels; + if (old_channels == channels) + return; + + pa_log_info("%s: channels: %u -> %u", s->name, old_channels, channels); + + s->sample_spec.channels = channels; + + 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; diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h index 64ea11f9d..8c67b2d4b 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_channels(pa_source *s, uint8_t channels); void pa_source_set_channel_map(pa_source *s, pa_channel_map *map); /*** To be called exclusively by the source driver, from IO context */