Fix #132905: High idle CPU usage with PulseAudio in Linux

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 bc39ee692d the previous fix got lost.

Co-authored-by: Jörg Müller <nexyon@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/132990
This commit is contained in:
Aras Pranckevicius 2025-01-13 14:33:15 +01:00
parent 3b28cf276e
commit e705073f94
2 changed files with 6 additions and 1 deletions

View file

@ -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)

View file

@ -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;