diff options
author | Julian Offenhäuser <metalvoidzz@gmail.com> | 2020-12-04 20:09:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-05 10:10:27 +0100 |
commit | 980acd0db7d41ec3799efe5a27ecbf7345d41c54 (patch) | |
tree | 02d761b066cddd879c9ae400540b2847d004fb68 /Services | |
parent | 745801e109d59b11da02ece7139570f7cc17e868 (diff) | |
download | serenity-980acd0db7d41ec3799efe5a27ecbf7345d41c54.zip |
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.
Diffstat (limited to 'Services')
-rw-r--r-- | Services/AudioServer/Mixer.cpp | 4 | ||||
-rw-r--r-- | Services/AudioServer/Mixer.h | 2 |
2 files changed, 5 insertions, 1 deletions
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<BufferQueue> 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 <AK/Atomic.h> #include <AK/Badge.h> #include <AK/ByteBuffer.h> #include <AK/NonnullRefPtrVector.h> @@ -125,6 +126,7 @@ public: private: Vector<NonnullRefPtr<BufferQueue>> m_pending_mixing; + Atomic<bool> m_added_queue { false }; pthread_mutex_t m_pending_mutex; pthread_cond_t m_pending_cond; |