Changed fillAndPushBuffer to use a retry loop.

This commit is contained in:
Cobaltergeist 2016-09-24 13:52:41 -07:00 committed by Lukas Dürrenberger
parent 77d19859bc
commit 746bb9c8ca
2 changed files with 28 additions and 22 deletions

View File

@ -282,7 +282,8 @@ private:
enum
{
BufferCount = 3 ///< Number of audio buffers used by the streaming loop
BufferCount = 3, ///< Number of audio buffers used by the streaming loop
BufferRetries = 2 ///< Number of retries (excluding initial try) for onGetData()
};
////////////////////////////////////////////////////////////

View File

@ -399,22 +399,28 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
{
bool requestStop = false;
// Acquire audio data
// Acquire audio data, also address EOF and error cases if they occur
Chunk data = {NULL, 0};
if (!onGetData(data))
for (Uint32 retryCount = 0; !onGetData(data) && (retryCount < BufferRetries); ++retryCount)
{
// Mark the buffer as the last one (so that we know when to reset the playing position)
m_endBuffers[bufferNum] = true;
// Check if the stream must loop or stop
if (m_loop)
if (!m_loop)
{
// Not looping: request stop
requestStop = true;
break;
}
// Return to the beginning of the stream source
onSeek(Time::Zero);
// If we previously had no data, try to fill the buffer once again
if (!data.samples || (data.sampleCount == 0))
{
// If we got data, break and process it, else try to fill the buffer once again
if (data.samples && data.sampleCount)
break;
// If immediateLoop is specified, we have to immediately adjust the sample count
if (immediateLoop)
{
@ -422,14 +428,8 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
m_samplesProcessed = 0;
m_endBuffers[bufferNum] = false;
}
return fillAndPushBuffer(bufferNum);
}
}
else
{
// Not looping: request stop
requestStop = true;
}
// We're a looping sound that got no data, so we retry onGetData()
}
// Fill the buffer if some data was returned
@ -444,6 +444,11 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
// Push it into the sound queue
alCheck(alSourceQueueBuffers(m_source, 1, &buffer));
}
else
{
// If we get here, we most likely ran out of retries
requestStop = true;
}
return requestStop;
}