1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a fix for a potential wrap-around bug in BufferingAudioSource

This commit is contained in:
hogliux 2016-11-22 11:44:11 +00:00
parent 61fd2a339d
commit 8154ccc4e5

View file

@ -168,9 +168,12 @@ bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelI
return true;
uint32 now = Time::getMillisecondCounter();
const uint32 endTime = now + timeout;
const uint32 startTime = now;
while (now <= endTime)
uint32 elapsed = (now >= startTime ? now - startTime
: (std::numeric_limits<uint32>::max() - startTime) + now);
while (elapsed <= timeout)
{
{
const ScopedLock sl (bufferStartPosLock);
@ -182,10 +185,14 @@ bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelI
return true;
}
if (endTime > now && (! bufferReadyEvent.wait (static_cast<int> (endTime - now))))
if (elapsed < timeout && (! bufferReadyEvent.wait (static_cast<int> (timeout - elapsed))))
return false;
now = Time::getMillisecondCounter();
elapsed = (now >= startTime ? now - startTime
: (std::numeric_limits<uint32>::max() - startTime) + now);
}
return false;