pulse-server: track volume/mute changes

When something else changes the volume of our stream, store the new
value in our volume/mute state so that we always have an up-to-date
value when we compare our volume to the desired volume.

See #721
This commit is contained in:
Wim Taymans 2021-02-16 17:21:26 +01:00
parent 6079830591
commit 3aa0a39e30

View file

@ -1316,6 +1316,24 @@ static int reply_create_record_stream(struct stream *stream)
return send_message(client, reply); return send_message(client, reply);
} }
static void stream_control_info(void *data, uint32_t id,
const struct pw_stream_control *control)
{
struct stream *stream = data;
switch (id) {
case SPA_PROP_channelVolumes:
stream->volume.channels = control->n_values;
memcpy(stream->volume.values, control->values, control->n_values * sizeof(float));
pw_log_info("stream %p: volume changed %f", stream, stream->volume.values[0]);
break;
case SPA_PROP_mute:
stream->muted = control->values[0] >= 0.5;
pw_log_info("stream %p: mute changed %d", stream, stream->muted);
break;
}
}
static void stream_state_changed(void *data, enum pw_stream_state old, static void stream_state_changed(void *data, enum pw_stream_state old,
enum pw_stream_state state, const char *error) enum pw_stream_state state, const char *error)
{ {
@ -1665,6 +1683,7 @@ static void stream_drained(void *data)
static const struct pw_stream_events stream_events = static const struct pw_stream_events stream_events =
{ {
PW_VERSION_STREAM_EVENTS, PW_VERSION_STREAM_EVENTS,
.control_info = stream_control_info,
.state_changed = stream_state_changed, .state_changed = stream_state_changed,
.param_changed = stream_param_changed, .param_changed = stream_param_changed,
.io_changed = stream_io_changed, .io_changed = stream_io_changed,
@ -2876,9 +2895,6 @@ static int do_set_stream_volume(struct client *client, uint32_t command, uint32_
if (volume_compare(&stream->volume, &volume) == 0) if (volume_compare(&stream->volume, &volume) == 0)
goto done; goto done;
stream->volume = volume;
stream->volume_set = true;
pw_stream_set_control(stream->stream, pw_stream_set_control(stream->stream,
SPA_PROP_channelVolumes, volume.channels, volume.values, SPA_PROP_channelVolumes, volume.channels, volume.values,
0); 0);
@ -2926,13 +2942,10 @@ static int do_set_stream_mute(struct client *client, uint32_t command, uint32_t
if (stream != NULL) { if (stream != NULL) {
float val; float val;
if (stream->muted == mute) goto done; if (stream->muted == mute)
goto done;
stream->muted = mute;
stream->muted_set = true;
val = mute ? 1.0f : 0.0f; val = mute ? 1.0f : 0.0f;
pw_stream_set_control(stream->stream, pw_stream_set_control(stream->stream,
SPA_PROP_mute, 1, &val, SPA_PROP_mute, 1, &val,
0); 0);