From 64b64b61be507f8dbfcda91c8fed2f374b3aef81 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 25 Dec 2021 20:37:52 +1100 Subject: [PATCH] [client] audio/pw: implement volume and mute control --- client/audiodevs/PipeWire/pipewire.c | 39 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 6604ff1e..e6fe4625 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -21,6 +21,7 @@ #include "interface/audiodev.h" #include +#include #include #include "common/debug.h" @@ -236,12 +237,38 @@ static void pipewire_stop(void) pw_thread_loop_unlock(pw.thread); } +static void pipewire_volume(int channels, const uint16_t volume[]) +{ + if (channels != pw.channels) + return; + + float param[channels]; + for(int i = 0; i < channels; ++i) + { + //TODO: the scaling here is wrong and needs fixing + param[i] = (1.0f / 65535.0f) * volume[i]; + } + + pw_thread_loop_lock(pw.thread); + pw_stream_set_control(pw.stream, SPA_PROP_channelVolumes, channels, param, 0); + pw_thread_loop_unlock(pw.thread); +} + +static void pipewire_mute(bool mute) +{ + pw_thread_loop_lock(pw.thread); + pw_stream_set_control(pw.stream, SPA_PROP_mute, 1, (void *)&mute, 0); + pw_thread_loop_unlock(pw.thread); +} + struct LG_AudioDevOps LGAD_PipeWire = { - .name = "PipeWire", - .init = pipewire_init, - .free = pipewire_free, - .start = pipewire_start, - .play = pipewire_play, - .stop = pipewire_stop + .name = "PipeWire", + .init = pipewire_init, + .free = pipewire_free, + .start = pipewire_start, + .play = pipewire_play, + .stop = pipewire_stop, + .volume = pipewire_volume, + .mute = pipewire_mute };