From e705073f94c5f03717b349c94487c37e770a05e2 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Mon, 13 Jan 2025 14:33:15 +0100 Subject: [PATCH] Fix #132905: High idle CPU usage with PulseAudio in Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents the unnecessary calls to CPU intensive PulseAudio functions while the stream is corked. This is re-applying PR #129312 since during Audaspace upstream update in bc39ee692d44 the previous fix got lost. Co-authored-by: Jörg Müller Pull Request: https://projects.blender.org/blender/blender/pulls/132990 --- 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 d26afeb9066..65acd222c44 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp @@ -94,12 +94,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; } } } @@ -163,12 +164,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 b6e6a313a74..37a3897c0da 100644 --- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h +++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.h @@ -66,6 +66,8 @@ private: */ volatile bool m_playback; + bool m_corked; + pa_threaded_mainloop* m_mainloop; pa_context* m_context; pa_stream* m_stream;