From 792d6584b99427f7503b088decf9f8e184518f46 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 8 Jul 2022 17:59:52 +0200 Subject: [PATCH] output/PipeWire: move code to OnChannelVolumes() --- src/output/plugins/PipeWireOutputPlugin.cxx | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/output/plugins/PipeWireOutputPlugin.cxx b/src/output/plugins/PipeWireOutputPlugin.cxx index 601f6585b..d187a5bc9 100644 --- a/src/output/plugins/PipeWireOutputPlugin.cxx +++ b/src/output/plugins/PipeWireOutputPlugin.cxx @@ -222,11 +222,11 @@ private: o.Drained(); } - void ControlInfo(const struct pw_stream_control *control) noexcept { - float sum = std::accumulate(control->values, - control->values + control->n_values, + void OnChannelVolumes(const struct pw_stream_control &control) noexcept { + float sum = std::accumulate(control.values, + control.values + control.n_values, 0.0f); - volume = std::cbrt(sum / control->n_values); + volume = std::cbrt(sum / control.n_values); if (mixer != nullptr) pipewire_mixer_on_change(*mixer, volume); @@ -234,13 +234,17 @@ private: pw_thread_loop_signal(thread_loop, false); } - static void ControlInfo(void *data, - [[maybe_unused]] uint32_t id, + void ControlInfo([[maybe_unused]] uint32_t id, + const struct pw_stream_control &control) noexcept { + if (control.name != nullptr && + StringIsEqual(control.name, "Channel Volumes")) + OnChannelVolumes(control); + } + + static void ControlInfo(void *data, uint32_t id, const struct pw_stream_control *control) noexcept { auto &o = *(PipeWireOutput *)data; - if (control->name != nullptr && - StringIsEqual(control->name, "Channel Volumes")) - o.ControlInfo(control); + o.ControlInfo(id, *control); } #if defined(ENABLE_DSD) && defined(SPA_AUDIO_DSD_FLAG_NONE)