From 980acd0db7d41ec3799efe5a27ecbf7345d41c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Fri, 4 Dec 2020 20:09:22 +0100 Subject: AudioServer: Fix issue when adding a BufferQueue to Mixer Previously, the Mixer class would only check for an added BufferQueue if the list of active queues was empty. If more than one client connected to AudioServer, its queue would never be added to the list of active queues. This fix adds a flag that, when set, will cause the sound thread to wait for a new BufferQueue. --- Services/AudioServer/Mixer.cpp | 4 +++- Services/AudioServer/Mixer.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Services/AudioServer/Mixer.cpp b/Services/AudioServer/Mixer.cpp index 664be197dc..894897cf63 100644 --- a/Services/AudioServer/Mixer.cpp +++ b/Services/AudioServer/Mixer.cpp @@ -64,6 +64,7 @@ NonnullRefPtr Mixer::create_queue(ClientConnection& client) auto queue = adopt(*new BufferQueue(client)); pthread_mutex_lock(&m_pending_mutex); m_pending_mixing.append(*queue); + m_added_queue = true; pthread_cond_signal(&m_pending_cond); pthread_mutex_unlock(&m_pending_mutex); return queue; @@ -74,11 +75,12 @@ void Mixer::mix() decltype(m_pending_mixing) active_mix_queues; for (;;) { - if (active_mix_queues.is_empty()) { + if (active_mix_queues.is_empty() || m_added_queue) { pthread_mutex_lock(&m_pending_mutex); pthread_cond_wait(&m_pending_cond, &m_pending_mutex); active_mix_queues.append(move(m_pending_mixing)); pthread_mutex_unlock(&m_pending_mutex); + m_added_queue = false; } active_mix_queues.remove_all_matching([&](auto& entry) { return !entry->client(); }); diff --git a/Services/AudioServer/Mixer.h b/Services/AudioServer/Mixer.h index 427b9eca27..fdad64d60a 100644 --- a/Services/AudioServer/Mixer.h +++ b/Services/AudioServer/Mixer.h @@ -27,6 +27,7 @@ #pragma once #include "ClientConnection.h" +#include #include #include #include @@ -125,6 +126,7 @@ public: private: Vector> m_pending_mixing; + Atomic m_added_queue { false }; pthread_mutex_t m_pending_mutex; pthread_cond_t m_pending_cond; -- cgit v1.2.3