Prevent us from consuming more than 4 samples per write callback to bound latency
This commit is contained in:
parent
a848fb1dd1
commit
5288041da5
1 changed files with 7 additions and 3 deletions
|
|
@ -386,15 +386,19 @@ void SoundIoAudioRenderer::sioWriteCallback(SoundIoOutStream* stream, int frameC
|
||||||
(me->m_OpusChannelCount * stream->bytes_per_sample);
|
(me->m_OpusChannelCount * stream->bytes_per_sample);
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
|
|
||||||
// Clamp framesLeft to frameCountMax
|
|
||||||
framesLeft = qMin(framesLeft, frameCountMax);
|
|
||||||
|
|
||||||
// Ensure we always write at least a buffer, even if it's silence, to avoid
|
// Ensure we always write at least a buffer, even if it's silence, to avoid
|
||||||
// busy looping when no audio data is available while libsoundio tries to keep
|
// busy looping when no audio data is available while libsoundio tries to keep
|
||||||
// us from starving the output device.
|
// us from starving the output device.
|
||||||
frameCountMin = qMax(frameCountMin, (int)(stream->sample_rate * k_MinSampleLengthSec));
|
frameCountMin = qMax(frameCountMin, (int)(stream->sample_rate * k_MinSampleLengthSec));
|
||||||
|
|
||||||
|
// Clamp frameCountMax to minSampleLen * 4 to stop our latency from growing if audio packets lag.
|
||||||
|
// This makes sure that we never increase our latency far beyond what the sink is consuming.
|
||||||
|
frameCountMax = qMin(frameCountMax, (int)(stream->sample_rate * k_MinSampleLengthSec) * 4);
|
||||||
frameCountMin = qMin(frameCountMin, frameCountMax);
|
frameCountMin = qMin(frameCountMin, frameCountMax);
|
||||||
|
|
||||||
|
// Clamp framesLeft to frameCountMax
|
||||||
|
framesLeft = qMin(framesLeft, frameCountMax);
|
||||||
|
|
||||||
// Track latency on queueing-based backends
|
// Track latency on queueing-based backends
|
||||||
if (me->m_SoundIo->current_backend != SoundIoBackendCoreAudio && me->m_SoundIo->current_backend != SoundIoBackendJack) {
|
if (me->m_SoundIo->current_backend != SoundIoBackendCoreAudio && me->m_SoundIo->current_backend != SoundIoBackendJack) {
|
||||||
soundio_outstream_get_latency(stream, &me->m_Latency);
|
soundio_outstream_get_latency(stream, &me->m_Latency);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue