From 477b45be1be256b7496e1d45b41754c6e40ef58a Mon Sep 17 00:00:00 2001 From: Maki Date: Fri, 19 Apr 2024 02:32:29 -0400 Subject: Add toggle for PipeWire volume catcher, and refactoring --- .../cef/linux/volume_catcher_linux.cpp | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 indra/media_plugins/cef/linux/volume_catcher_linux.cpp (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.cpp') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp new file mode 100644 index 0000000000..86cc329e66 --- /dev/null +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp @@ -0,0 +1,103 @@ +/** + * @file volume_catcher.cpp + * @brief Linux volume catcher which will pick an implementation to use + * + * @cond + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + * @endcond + */ + +#include "volume_catcher_linux.h" + +#define PULSEAUDIO pimpl +#define PIPEWIRE pimpl2 + +//////////////////////////////////////////////////// + +VolumeCatcher::VolumeCatcher() +{ + // only init once we receive which implementation to use + + // debugClear(); + // debugPrint("init volume catcher\n"); +} + +void VolumeCatcher::onEnablePipeWireVolumeCatcher(bool enable) { + if (enable) { + // load pipewire + + if (PULSEAUDIO != nullptr) { + delete PULSEAUDIO; + PULSEAUDIO = nullptr; + } + + if (PIPEWIRE == nullptr) { + // debugPrint("volume catcher using pipewire\n"); + PIPEWIRE = new VolumeCatcherPipeWire(); + } + } else { + // load pulseaudio + + if (PIPEWIRE != nullptr) { + delete PIPEWIRE; + PIPEWIRE = nullptr; + } + + if (PULSEAUDIO == nullptr) { + // debugPrint("volume catcher using pulseaudio\n"); + PULSEAUDIO = new VolumeCatcherPulseAudio(); + } + } +} + +VolumeCatcher::~VolumeCatcher() +{ + if (PULSEAUDIO != nullptr) { + delete PULSEAUDIO; + PULSEAUDIO = nullptr; + } + + if (PIPEWIRE != nullptr) { + delete PIPEWIRE; + PIPEWIRE = nullptr; + } +} + +void VolumeCatcher::setVolume(F32 volume) +{ + if (PULSEAUDIO != nullptr) PULSEAUDIO->setVolume(volume); + if (PIPEWIRE != nullptr) PIPEWIRE->setVolume(volume); +} + +void VolumeCatcher::setPan(F32 pan) +{ + // not implemented for both + // if (PULSEAUDIO) PULSEAUDIO->setPan(pan); + // if (PIPEWIRE) PIPEWIRE->setPan(pan); +} + +void VolumeCatcher::pump() +{ + if (PULSEAUDIO != nullptr) PULSEAUDIO->pump(); + if (PIPEWIRE != nullptr) PIPEWIRE->pump(); // doesn't need it +} + -- cgit v1.2.3 From e6ca21549ee1d4a23c82e12d9215ce993d99ca3e Mon Sep 17 00:00:00 2001 From: Maki Date: Sat, 20 Apr 2024 17:50:43 -0400 Subject: Only use one impl in Linux volume catcher --- .../cef/linux/volume_catcher_linux.cpp | 59 +++++++--------------- 1 file changed, 19 insertions(+), 40 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.cpp') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp index 86cc329e66..3c037b45ba 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp @@ -28,9 +28,6 @@ #include "volume_catcher_linux.h" -#define PULSEAUDIO pimpl -#define PIPEWIRE pimpl2 - //////////////////////////////////////////////////// VolumeCatcher::VolumeCatcher() @@ -42,62 +39,44 @@ VolumeCatcher::VolumeCatcher() } void VolumeCatcher::onEnablePipeWireVolumeCatcher(bool enable) { - if (enable) { - // load pipewire - - if (PULSEAUDIO != nullptr) { - delete PULSEAUDIO; - PULSEAUDIO = nullptr; - } + if (pimpl != nullptr) + return; - if (PIPEWIRE == nullptr) { - // debugPrint("volume catcher using pipewire\n"); - PIPEWIRE = new VolumeCatcherPipeWire(); - } + if (enable) { + // debugPrint("volume catcher using pipewire\n"); + pimpl = new VolumeCatcherPipeWire(); } else { - // load pulseaudio - - if (PIPEWIRE != nullptr) { - delete PIPEWIRE; - PIPEWIRE = nullptr; - } - - if (PULSEAUDIO == nullptr) { - // debugPrint("volume catcher using pulseaudio\n"); - PULSEAUDIO = new VolumeCatcherPulseAudio(); - } + // debugPrint("volume catcher using pulseaudio\n"); + pimpl = new VolumeCatcherPulseAudio(); } } VolumeCatcher::~VolumeCatcher() { - if (PULSEAUDIO != nullptr) { - delete PULSEAUDIO; - PULSEAUDIO = nullptr; - } - - if (PIPEWIRE != nullptr) { - delete PIPEWIRE; - PIPEWIRE = nullptr; + if (pimpl != nullptr) { + delete pimpl; + pimpl = nullptr; } } void VolumeCatcher::setVolume(F32 volume) { - if (PULSEAUDIO != nullptr) PULSEAUDIO->setVolume(volume); - if (PIPEWIRE != nullptr) PIPEWIRE->setVolume(volume); + if (pimpl != nullptr) { + pimpl->setVolume(volume); + } } void VolumeCatcher::setPan(F32 pan) { - // not implemented for both - // if (PULSEAUDIO) PULSEAUDIO->setPan(pan); - // if (PIPEWIRE) PIPEWIRE->setPan(pan); + if (pimpl != nullptr) { + pimpl->setPan(pan); + } } void VolumeCatcher::pump() { - if (PULSEAUDIO != nullptr) PULSEAUDIO->pump(); - if (PIPEWIRE != nullptr) PIPEWIRE->pump(); // doesn't need it + if (pimpl != nullptr) { + pimpl->pump(); + } } -- cgit v1.2.3 From 19c6368991706d1bcb4a3b02e08cd70e1e6324c7 Mon Sep 17 00:00:00 2001 From: Nicky Date: Sun, 21 Apr 2024 18:50:38 +0200 Subject: Stream the volume catcher a little: - Use LL_DEBUGS() for potential debug output. - Enclose mutex locking in their own scope, to make unlocking automatic and also limit the life time of a lock to as short as possible - Introduce mCleanupMutex to replace std::unique_lock pwLock(*this). I'm baffled using lock as a mutex like that did even compile. - Remove virtual inheritance, as it is not needed here. --- .../cef/linux/volume_catcher_linux.cpp | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.cpp') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp index 3c037b45ba..439c0a6768 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp @@ -32,28 +32,29 @@ VolumeCatcher::VolumeCatcher() { - // only init once we receive which implementation to use - - // debugClear(); - // debugPrint("init volume catcher\n"); } -void VolumeCatcher::onEnablePipeWireVolumeCatcher(bool enable) { +void VolumeCatcher::onEnablePipeWireVolumeCatcher(bool enable) +{ if (pimpl != nullptr) return; - if (enable) { - // debugPrint("volume catcher using pipewire\n"); + if (enable) + { + LL_DEBUGS() << "volume catcher using pipewire" << LL_ENDL; pimpl = new VolumeCatcherPipeWire(); - } else { - // debugPrint("volume catcher using pulseaudio\n"); + } + else + { + LL_DEBUGS() << "volume catcher using pulseaudio" << LL_ENDL; pimpl = new VolumeCatcherPulseAudio(); } } VolumeCatcher::~VolumeCatcher() { - if (pimpl != nullptr) { + if (pimpl != nullptr) + { delete pimpl; pimpl = nullptr; } @@ -68,15 +69,12 @@ void VolumeCatcher::setVolume(F32 volume) void VolumeCatcher::setPan(F32 pan) { - if (pimpl != nullptr) { + if (pimpl != nullptr) pimpl->setPan(pan); - } } void VolumeCatcher::pump() { - if (pimpl != nullptr) { + if (pimpl != nullptr) pimpl->pump(); - } } - -- cgit v1.2.3 From 3dc5fa00753bb889280771a2cd17029aa1e42f24 Mon Sep 17 00:00:00 2001 From: Nicky Date: Mon, 22 Apr 2024 09:32:54 +0200 Subject: Tabs to spaces --- .../cef/linux/volume_catcher_linux.cpp | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.cpp') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp index 439c0a6768..b4d20935e7 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp @@ -36,45 +36,45 @@ VolumeCatcher::VolumeCatcher() void VolumeCatcher::onEnablePipeWireVolumeCatcher(bool enable) { - if (pimpl != nullptr) - return; + if (pimpl != nullptr) + return; - if (enable) + if (enable) { - LL_DEBUGS() << "volume catcher using pipewire" << LL_ENDL; - pimpl = new VolumeCatcherPipeWire(); - } + LL_DEBUGS() << "volume catcher using pipewire" << LL_ENDL; + pimpl = new VolumeCatcherPipeWire(); + } else { - LL_DEBUGS() << "volume catcher using pulseaudio" << LL_ENDL; - pimpl = new VolumeCatcherPulseAudio(); - } + LL_DEBUGS() << "volume catcher using pulseaudio" << LL_ENDL; + pimpl = new VolumeCatcherPulseAudio(); + } } VolumeCatcher::~VolumeCatcher() { - if (pimpl != nullptr) + if (pimpl != nullptr) { - delete pimpl; - pimpl = nullptr; - } + delete pimpl; + pimpl = nullptr; + } } void VolumeCatcher::setVolume(F32 volume) { - if (pimpl != nullptr) { - pimpl->setVolume(volume); - } + if (pimpl != nullptr) { + pimpl->setVolume(volume); + } } void VolumeCatcher::setPan(F32 pan) { - if (pimpl != nullptr) - pimpl->setPan(pan); + if (pimpl != nullptr) + pimpl->setPan(pan); } void VolumeCatcher::pump() { - if (pimpl != nullptr) - pimpl->pump(); + if (pimpl != nullptr) + pimpl->pump(); } -- cgit v1.2.3 From 7d62d0c5752814f27a17c86618f628d0e4ff9b0d Mon Sep 17 00:00:00 2001 From: Nicky Date: Wed, 22 May 2024 13:20:39 +0200 Subject: Move Linux specific VolumeCatcherImport into the linux specific files. --- indra/media_plugins/cef/linux/volume_catcher_linux.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.cpp') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp index b4d20935e7..7d33242063 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.cpp +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.cpp @@ -1,4 +1,4 @@ -/** +/** * @file volume_catcher.cpp * @brief Linux volume catcher which will pick an implementation to use * @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2010&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ * @endcond @@ -28,8 +28,6 @@ #include "volume_catcher_linux.h" -//////////////////////////////////////////////////// - VolumeCatcher::VolumeCatcher() { } -- cgit v1.2.3