Audaspace: Bugfix for PulseAudio ported from upstream.

This commit is contained in:
Jörg Müller 2024-03-08 16:31:47 +01:00
parent 930b11b0fe
commit 91eb50ec2f
4 changed files with 25 additions and 0 deletions

View File

@ -74,6 +74,8 @@ public:
size_t write(data_t* source, size_t size);
void clear();
/**
* Resets the ring buffer to a state where nothing has been written or read.
*/

View File

@ -91,6 +91,12 @@ void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t total_bytes,
AUD_pa_stream_begin_write(stream, reinterpret_cast<void**>(&buffer), &num_bytes);
if(device->m_clear)
{
device->m_clear = false;
device->m_ring_buffer.clear();
}
size_t readsamples = device->m_ring_buffer.getReadSize();
readsamples = std::min(readsamples, size_t(num_bytes)) / sample_size;
@ -119,11 +125,18 @@ void PulseAudioDevice::playing(bool playing)
AUD_pa_threaded_mainloop_lock(m_mainloop);
AUD_pa_stream_cork(m_stream, playing ? 0 : 1, nullptr, nullptr);
AUD_pa_threaded_mainloop_unlock(m_mainloop);
if(!playing)
{
AUD_pa_stream_flush(m_stream, nullptr, nullptr);
m_clear = true;
}
}
PulseAudioDevice::PulseAudioDevice(const std::string &name, DeviceSpecs specs, int buffersize) :
m_synchronizer(this),
m_playback(false),
m_clear(false),
m_state(PA_CONTEXT_UNCONNECTED),
m_valid(true),
m_underflows(0)

View File

@ -60,6 +60,11 @@ private:
*/
volatile bool m_playback;
/**
* Set when playback is paused in order to later clear the ring buffer when the playback starts again.
*/
volatile bool m_clear;
pa_threaded_mainloop* m_mainloop;
pa_context* m_context;
pa_stream* m_stream;

View File

@ -116,6 +116,11 @@ size_t RingBuffer::write(data_t* source, size_t size)
return size;
}
void RingBuffer::clear()
{
m_read = m_write;
}
void RingBuffer::reset()
{
m_read = 0;