From d5b13a1de2ea886d6b9d6773bae694b24137fc8d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 13 Aug 2019 18:46:27 +0200 Subject: [PATCH] stream: improve control update When setting the volume, update the stream controls with the new values and update the internal state with the control_info event. --- src/introspect.c | 11 ++--------- src/stream.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/introspect.c b/src/introspect.c index 20f110687..d53149783 100644 --- a/src/introspect.c +++ b/src/introspect.c @@ -275,17 +275,10 @@ static void set_stream_volume(pa_context *c, pa_stream *s, const pa_cvolume *vol if (n_channel_volumes != s->n_channel_volumes || !memcmp(s->channel_volumes, vols, n_channel_volumes * sizeof(float)) || s->mute != mute) { - float val; - - memcpy(s->channel_volumes, vols, n_channel_volumes * sizeof(float)); - s->n_channel_volumes = n_channel_volumes; - s->mute = mute; - - val = s->mute ? 1.0f : 0.0f; - + float val = s->mute ? 1.0f : 0.0f; pw_stream_set_control(s->stream, SPA_PROP_mute, 1, &val, - SPA_PROP_channelVolumes, n_channel_volumes, channel_volumes, + SPA_PROP_channelVolumes, n_channel_volumes, vols, 0); } } diff --git a/src/stream.c b/src/stream.c index 35297f346..4dafcd698 100644 --- a/src/stream.c +++ b/src/stream.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -414,6 +415,24 @@ static void stream_format_changed(void *data, const struct spa_pod *format) pw_stream_finish_format(s->stream, res, params, n_params); } +static void stream_control_info(void *data, uint32_t id, const struct pw_stream_control *control) +{ + pa_stream *s = data; + + switch (id) { + case SPA_PROP_mute: + if (control->n_values > 0) + s->mute = control->values[0] >= 0.5f; + break; + case SPA_PROP_channelVolumes: + s->n_channel_volumes = SPA_MAX(SPA_AUDIO_MAX_CHANNELS, control->n_values); + memcpy(s->channel_volumes, control->values, s->n_channel_volumes * sizeof(float)); + break; + default: + break; + } +} + static void stream_add_buffer(void *data, struct pw_buffer *buffer) { pa_stream *s = data; @@ -503,6 +522,7 @@ static const struct pw_stream_events stream_events = PW_VERSION_STREAM_EVENTS, .state_changed = stream_state_changed, .format_changed = stream_format_changed, + .control_info = stream_control_info, .add_buffer = stream_add_buffer, .remove_buffer = stream_remove_buffer, .process = stream_process,