From 3b8bd516e9d20d6bbcdcfa614b790fde8a32beb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20M=C3=BCller?= Date: Mon, 21 Oct 2024 00:51:31 +0200 Subject: [PATCH] Fix #129162: High idle CPU usage with PulseAudio in Linux --- extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp | 5 ++++- extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp index 06db7d84f12..bfe67d245f6 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp @@ -71,12 +71,13 @@ void PulseAudioDevice::updateRingBuffer() } else { - if(m_ring_buffer.getReadSize() == 0) + if(m_ring_buffer.getReadSize() == 0 && !m_corked) { AUD_pa_threaded_mainloop_lock(m_mainloop); AUD_pa_stream_cork(m_stream, 1, nullptr, nullptr); AUD_pa_stream_flush(m_stream, nullptr, nullptr); AUD_pa_threaded_mainloop_unlock(m_mainloop); + m_corked = true; } } } @@ -140,12 +141,14 @@ void PulseAudioDevice::playing(bool playing) AUD_pa_threaded_mainloop_lock(m_mainloop); AUD_pa_stream_cork(m_stream, 0, nullptr, nullptr); AUD_pa_threaded_mainloop_unlock(m_mainloop); + m_corked = false; } } PulseAudioDevice::PulseAudioDevice(const std::string &name, DeviceSpecs specs, int buffersize) : m_synchronizer(this), m_playback(false), + m_corked(true), m_state(PA_CONTEXT_UNCONNECTED), m_valid(true), m_underflows(0) diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h index 23306168173..ce5aa7fbdff 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h @@ -60,6 +60,8 @@ private: */ volatile bool m_playback; + bool m_corked; + pa_threaded_mainloop* m_mainloop; pa_context* m_context; pa_stream* m_stream;