mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-12 13:30:15 -05:00
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.
This commit is contained in:
parent
69ad904b63
commit
d5b13a1de2
2 changed files with 22 additions and 9 deletions
|
|
@ -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 ||
|
if (n_channel_volumes != s->n_channel_volumes ||
|
||||||
!memcmp(s->channel_volumes, vols, n_channel_volumes * sizeof(float)) ||
|
!memcmp(s->channel_volumes, vols, n_channel_volumes * sizeof(float)) ||
|
||||||
s->mute != mute) {
|
s->mute != mute) {
|
||||||
float val;
|
float val = s->mute ? 1.0f : 0.0f;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
pw_stream_set_control(s->stream,
|
pw_stream_set_control(s->stream,
|
||||||
SPA_PROP_mute, 1, &val,
|
SPA_PROP_mute, 1, &val,
|
||||||
SPA_PROP_channelVolumes, n_channel_volumes, channel_volumes,
|
SPA_PROP_channelVolumes, n_channel_volumes, vols,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
src/stream.c
20
src/stream.c
|
|
@ -22,6 +22,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <spa/utils/defs.h>
|
#include <spa/utils/defs.h>
|
||||||
|
#include <spa/param/props.h>
|
||||||
|
|
||||||
#include <pulse/stream.h>
|
#include <pulse/stream.h>
|
||||||
#include <pulse/timeval.h>
|
#include <pulse/timeval.h>
|
||||||
|
|
@ -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);
|
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)
|
static void stream_add_buffer(void *data, struct pw_buffer *buffer)
|
||||||
{
|
{
|
||||||
pa_stream *s = data;
|
pa_stream *s = data;
|
||||||
|
|
@ -503,6 +522,7 @@ static const struct pw_stream_events stream_events =
|
||||||
PW_VERSION_STREAM_EVENTS,
|
PW_VERSION_STREAM_EVENTS,
|
||||||
.state_changed = stream_state_changed,
|
.state_changed = stream_state_changed,
|
||||||
.format_changed = stream_format_changed,
|
.format_changed = stream_format_changed,
|
||||||
|
.control_info = stream_control_info,
|
||||||
.add_buffer = stream_add_buffer,
|
.add_buffer = stream_add_buffer,
|
||||||
.remove_buffer = stream_remove_buffer,
|
.remove_buffer = stream_remove_buffer,
|
||||||
.process = stream_process,
|
.process = stream_process,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue