From d0fdbefbfb60994ad8d6cf3b7129dcdd556c1924 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 8 Sep 2025 21:10:30 +1000 Subject: plugin/ap: fix collector Actually read from speakers not mic --- plugin/src/Caelestia/service.cpp | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'plugin/src/Caelestia/service.cpp') diff --git a/plugin/src/Caelestia/service.cpp b/plugin/src/Caelestia/service.cpp index 9c13421..5d5232b 100644 --- a/plugin/src/Caelestia/service.cpp +++ b/plugin/src/Caelestia/service.cpp @@ -1,6 +1,7 @@ #include "service.hpp" #include +#include #include namespace caelestia { @@ -9,30 +10,46 @@ Service::Service(QObject* parent) : QObject(parent) , m_refCount(0) {} -int Service::refCount() const { +int Service::refCount() { + QMutexLocker locker(&m_mutex); return m_refCount; } void Service::ref() { - if (m_refCount == 0) { - start(); + bool needsStart = false; + + { + QMutexLocker locker(&m_mutex); + if (m_refCount == 0) { + needsStart = true; + } + m_refCount++; } - - m_refCount++; emit refCountChanged(); + + if (needsStart) { + QMetaObject::invokeMethod(this, &Service::start, Qt::QueuedConnection); + } } void Service::unref() { - if (m_refCount == 0) { - qWarning() << "ServiceRef::unref: attempted to unref service with no active refs"; - return; + bool needsStop = false; + + { + QMutexLocker locker(&m_mutex); + if (m_refCount == 0) { + qWarning() << "ServiceRef::unref: attempted to unref service with no active refs"; + return; + } + m_refCount--; + if (m_refCount == 0) { + needsStop = true; + } } - - m_refCount--; emit refCountChanged(); - if (m_refCount == 0) { - stop(); + if (needsStop) { + QMetaObject::invokeMethod(this, &Service::stop, Qt::QueuedConnection); } } -- cgit v1.2.3-freya