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 --- .../media_plugins/cef/linux/volume_catcher_linux.h | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 indra/media_plugins/cef/linux/volume_catcher_linux.h (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h new file mode 100644 index 0000000000..5149dd62e0 --- /dev/null +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -0,0 +1,151 @@ +/** + * @file volume_catcher_impl.h + * @brief + * + * @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 + */ + +#ifndef VOLUME_CATCHER_LINUX_H +#define VOLUME_CATCHER_LINUX_H + +#include "linden_common.h" + +#include "../volume_catcher.h" + +#include +#include + +extern "C" { +// There's no special reason why we want the *glib* PA mainloop, but the generic polling implementation seems broken. +#include +#include + +#include + +#include "apr_pools.h" +#include "apr_dso.h" +} + +#include "media_plugin_base.h" + +class VolumeCatcherPulseAudio : public virtual VolumeCatcherImpl +{ +public: + VolumeCatcherPulseAudio(); + ~VolumeCatcherPulseAudio(); + + void setVolume(F32 volume); + void setPan(F32 pan); + void pump(); + + // for internal use - can't be private because used from our C callbacks + + bool loadsyms(std::string pa_dso_name); + void init(); + void cleanup(); + + void update_all_volumes(F32 volume); + void update_index_volume(U32 index, F32 volume); + void connected_okay(); + + std::set mSinkInputIndices; + std::map mSinkInputNumChannels; + F32 mDesiredVolume; + pa_glib_mainloop *mMainloop; + pa_context *mPAContext; + bool mConnected; + bool mGotSyms; +}; + +class VolumeCatcherPipeWire : public virtual VolumeCatcherImpl +{ +public: + VolumeCatcherPipeWire(); + ~VolumeCatcherPipeWire(); + + bool loadsyms(std::string pw_dso_name); + void init(); + void cleanup(); + + // some of these should be private + + void pwLock(); + void pwUnlock(); + + void setVolume(F32 volume); + void setPan(F32 pan); + void pump(); + + void handleRegistryEventGlobal( + uint32_t id, uint32_t permissions, const char* type, + uint32_t version, const struct spa_dict* props + ); + + class ChildNode + { + public: + bool mActive = false; + + pw_proxy* mProxy = nullptr; + spa_hook mNodeListener {}; + spa_hook mProxyListener {}; + VolumeCatcherPipeWire* mImpl = nullptr; + + void updateVolume(); + void destroy(); + }; + + bool mGotSyms = false; + + F32 mVolume = 1.0f; // max by default + // F32 mPan = 0.0f; // center + + pw_thread_loop* mThreadLoop; + pw_context* mContext; + pw_core* mCore; + pw_registry* mRegistry; + spa_hook mRegistryListener; + + std::unordered_set mChildNodes; + std::mutex mChildNodesMutex; +}; + +// static void debugClear() +// { +// auto file = fopen("volume-catcher-log.txt", "w"); +// fprintf(file, "\n"); +// fclose(file); +// } + +// static void debugPrint(const char* format, ...) +// { +// va_list args; +// va_start(args, format); +// auto file = fopen("volume-catcher-log.txt", "a"); +// vfprintf(file, format, args); +// fclose(file); +// va_end(args); +// } + +#endif // VOLUME_CATCHER_LINUX_H -- cgit v1.2.3 From 576508ebab789207c5d82c13ff627cb623d74994 Mon Sep 17 00:00:00 2001 From: Maki Date: Sat, 20 Apr 2024 17:35:30 -0400 Subject: Use RAII for mutexes for PipeWire volume catcher --- indra/media_plugins/cef/linux/volume_catcher_linux.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h index 5149dd62e0..0f11c537b1 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.h +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -90,8 +90,8 @@ public: // some of these should be private - void pwLock(); - void pwUnlock(); + void lock(); + void unlock(); void setVolume(F32 volume); void setPan(F32 pan); -- 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. --- .../media_plugins/cef/linux/volume_catcher_linux.h | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h index 0f11c537b1..ff00d0672e 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.h +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -49,7 +49,7 @@ extern "C" { #include "media_plugin_base.h" -class VolumeCatcherPulseAudio : public virtual VolumeCatcherImpl +class VolumeCatcherPulseAudio : public VolumeCatcherImpl { public: VolumeCatcherPulseAudio(); @@ -78,7 +78,7 @@ public: bool mGotSyms; }; -class VolumeCatcherPipeWire : public virtual VolumeCatcherImpl +class VolumeCatcherPipeWire : public VolumeCatcherImpl { public: VolumeCatcherPipeWire(); @@ -121,31 +121,15 @@ public: F32 mVolume = 1.0f; // max by default // F32 mPan = 0.0f; // center - pw_thread_loop* mThreadLoop; - pw_context* mContext; - pw_core* mCore; - pw_registry* mRegistry; + pw_thread_loop* mThreadLoop = nullptr; + pw_context* mContext = nullptr; + pw_core* mCore = nullptr; + pw_registry* mRegistry = nullptr; spa_hook mRegistryListener; std::unordered_set mChildNodes; std::mutex mChildNodesMutex; + std::mutex mCleanupMutex; }; -// static void debugClear() -// { -// auto file = fopen("volume-catcher-log.txt", "w"); -// fprintf(file, "\n"); -// fclose(file); -// } - -// static void debugPrint(const char* format, ...) -// { -// va_list args; -// va_start(args, format); -// auto file = fopen("volume-catcher-log.txt", "a"); -// vfprintf(file, format, args); -// fclose(file); -// va_end(args); -// } - #endif // VOLUME_CATCHER_LINUX_H -- 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. --- .../media_plugins/cef/linux/volume_catcher_linux.h | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h index ff00d0672e..9101575b70 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.h +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -1,26 +1,26 @@ -/** +/** * @file volume_catcher_impl.h - * @brief + * @brief * * @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 @@ -49,6 +49,20 @@ extern "C" { #include "media_plugin_base.h" +class VolumeCatcherImpl +{ +public: + virtual ~VolumeCatcherImpl() = default; + + virtual void setVolume(F32 volume) = 0; // 0.0 - 1.0 + + // Set the left-right pan of audio sources + // where -1.0 = left, 0 = center, and 1.0 = right + virtual void setPan(F32 pan) = 0; + + virtual void pump() = 0; // call this at least a few times a second if you can - it affects how quickly we can 'catch' a new audio source and adjust its volume +}; + class VolumeCatcherPulseAudio : public VolumeCatcherImpl { public: -- cgit v1.2.3 From 8789d372c7617d86a30395190db4dba3b8545226 Mon Sep 17 00:00:00 2001 From: Nicky Date: Wed, 22 May 2024 13:31:15 +0200 Subject: Tabs to spaces. --- .../media_plugins/cef/linux/volume_catcher_linux.h | 132 ++++++++++----------- 1 file changed, 66 insertions(+), 66 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h index 9101575b70..475e8ca52e 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.h +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -52,97 +52,97 @@ extern "C" { class VolumeCatcherImpl { public: - virtual ~VolumeCatcherImpl() = default; + virtual ~VolumeCatcherImpl() = default; - virtual void setVolume(F32 volume) = 0; // 0.0 - 1.0 + virtual void setVolume(F32 volume) = 0; // 0.0 - 1.0 - // Set the left-right pan of audio sources - // where -1.0 = left, 0 = center, and 1.0 = right - virtual void setPan(F32 pan) = 0; + // Set the left-right pan of audio sources + // where -1.0 = left, 0 = center, and 1.0 = right + virtual void setPan(F32 pan) = 0; - virtual void pump() = 0; // call this at least a few times a second if you can - it affects how quickly we can 'catch' a new audio source and adjust its volume + virtual void pump() = 0; // call this at least a few times a second if you can - it affects how quickly we can 'catch' a new audio source and adjust its volume }; class VolumeCatcherPulseAudio : public VolumeCatcherImpl { public: - VolumeCatcherPulseAudio(); - ~VolumeCatcherPulseAudio(); - - void setVolume(F32 volume); - void setPan(F32 pan); - void pump(); - - // for internal use - can't be private because used from our C callbacks - - bool loadsyms(std::string pa_dso_name); - void init(); - void cleanup(); - - void update_all_volumes(F32 volume); - void update_index_volume(U32 index, F32 volume); - void connected_okay(); - - std::set mSinkInputIndices; - std::map mSinkInputNumChannels; - F32 mDesiredVolume; - pa_glib_mainloop *mMainloop; - pa_context *mPAContext; - bool mConnected; - bool mGotSyms; + VolumeCatcherPulseAudio(); + ~VolumeCatcherPulseAudio(); + + void setVolume(F32 volume); + void setPan(F32 pan); + void pump(); + + // for internal use - can't be private because used from our C callbacks + + bool loadsyms(std::string pa_dso_name); + void init(); + void cleanup(); + + void update_all_volumes(F32 volume); + void update_index_volume(U32 index, F32 volume); + void connected_okay(); + + std::set mSinkInputIndices; + std::map mSinkInputNumChannels; + F32 mDesiredVolume; + pa_glib_mainloop *mMainloop; + pa_context *mPAContext; + bool mConnected; + bool mGotSyms; }; class VolumeCatcherPipeWire : public VolumeCatcherImpl { public: - VolumeCatcherPipeWire(); - ~VolumeCatcherPipeWire(); + VolumeCatcherPipeWire(); + ~VolumeCatcherPipeWire(); - bool loadsyms(std::string pw_dso_name); - void init(); - void cleanup(); + bool loadsyms(std::string pw_dso_name); + void init(); + void cleanup(); - // some of these should be private + // some of these should be private - void lock(); - void unlock(); + void lock(); + void unlock(); - void setVolume(F32 volume); - void setPan(F32 pan); - void pump(); + void setVolume(F32 volume); + void setPan(F32 pan); + void pump(); - void handleRegistryEventGlobal( - uint32_t id, uint32_t permissions, const char* type, - uint32_t version, const struct spa_dict* props - ); + void handleRegistryEventGlobal( + uint32_t id, uint32_t permissions, const char* type, + uint32_t version, const struct spa_dict* props + ); - class ChildNode - { - public: - bool mActive = false; + class ChildNode + { + public: + bool mActive = false; - pw_proxy* mProxy = nullptr; - spa_hook mNodeListener {}; - spa_hook mProxyListener {}; - VolumeCatcherPipeWire* mImpl = nullptr; + pw_proxy* mProxy = nullptr; + spa_hook mNodeListener {}; + spa_hook mProxyListener {}; + VolumeCatcherPipeWire* mImpl = nullptr; - void updateVolume(); - void destroy(); - }; + void updateVolume(); + void destroy(); + }; - bool mGotSyms = false; + bool mGotSyms = false; - F32 mVolume = 1.0f; // max by default - // F32 mPan = 0.0f; // center + F32 mVolume = 1.0f; // max by default + // F32 mPan = 0.0f; // center - pw_thread_loop* mThreadLoop = nullptr; - pw_context* mContext = nullptr; - pw_core* mCore = nullptr; - pw_registry* mRegistry = nullptr; - spa_hook mRegistryListener; + pw_thread_loop* mThreadLoop = nullptr; + pw_context* mContext = nullptr; + pw_core* mCore = nullptr; + pw_registry* mRegistry = nullptr; + spa_hook mRegistryListener; - std::unordered_set mChildNodes; - std::mutex mChildNodesMutex; + std::unordered_set mChildNodes; + std::mutex mChildNodesMutex; std::mutex mCleanupMutex; }; -- cgit v1.2.3 From bdf46af9aff96a749dcf2612a2bdc6e8e394971e Mon Sep 17 00:00:00 2001 From: AiraYumi Date: Tue, 21 May 2024 20:52:38 -0400 Subject: fix "lines starting with tabs found" --- indra/media_plugins/cef/linux/volume_catcher_linux.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/media_plugins/cef/linux/volume_catcher_linux.h') diff --git a/indra/media_plugins/cef/linux/volume_catcher_linux.h b/indra/media_plugins/cef/linux/volume_catcher_linux.h index 475e8ca52e..505f9ffb31 100644 --- a/indra/media_plugins/cef/linux/volume_catcher_linux.h +++ b/indra/media_plugins/cef/linux/volume_catcher_linux.h @@ -112,22 +112,22 @@ public: void pump(); void handleRegistryEventGlobal( - uint32_t id, uint32_t permissions, const char* type, - uint32_t version, const struct spa_dict* props + uint32_t id, uint32_t permissions, const char* type, + uint32_t version, const struct spa_dict* props ); class ChildNode { public: - bool mActive = false; + bool mActive = false; - pw_proxy* mProxy = nullptr; - spa_hook mNodeListener {}; - spa_hook mProxyListener {}; - VolumeCatcherPipeWire* mImpl = nullptr; + pw_proxy* mProxy = nullptr; + spa_hook mNodeListener {}; + spa_hook mProxyListener {}; + VolumeCatcherPipeWire* mImpl = nullptr; - void updateVolume(); - void destroy(); + void updateVolume(); + void destroy(); }; bool mGotSyms = false; -- cgit v1.2.3