mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Changed fillAndPushBuffer to use a retry loop.
This commit is contained in:
parent
77d19859bc
commit
746bb9c8ca
@ -282,7 +282,8 @@ private:
|
|||||||
|
|
||||||
enum
|
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()
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -399,37 +399,37 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
|
|||||||
{
|
{
|
||||||
bool requestStop = false;
|
bool requestStop = false;
|
||||||
|
|
||||||
// Acquire audio data
|
// Acquire audio data, also address EOF and error cases if they occur
|
||||||
Chunk data = {NULL, 0};
|
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)
|
// Mark the buffer as the last one (so that we know when to reset the playing position)
|
||||||
m_endBuffers[bufferNum] = true;
|
m_endBuffers[bufferNum] = true;
|
||||||
|
|
||||||
// Check if the stream must loop or stop
|
// Check if the stream must loop or stop
|
||||||
if (m_loop)
|
if (!m_loop)
|
||||||
{
|
|
||||||
// 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 immediateLoop is specified, we have to immediately adjust the sample count
|
|
||||||
if (immediateLoop)
|
|
||||||
{
|
|
||||||
// We just tried to begin preloading at EOF: reset the sample count
|
|
||||||
m_samplesProcessed = 0;
|
|
||||||
m_endBuffers[bufferNum] = false;
|
|
||||||
}
|
|
||||||
return fillAndPushBuffer(bufferNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Not looping: request stop
|
// Not looping: request stop
|
||||||
requestStop = true;
|
requestStop = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return to the beginning of the stream source
|
||||||
|
onSeek(Time::Zero);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
// We just tried to begin preloading at EOF: reset the sample count
|
||||||
|
m_samplesProcessed = 0;
|
||||||
|
m_endBuffers[bufferNum] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're a looping sound that got no data, so we retry onGetData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill the buffer if some data was returned
|
// 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
|
// Push it into the sound queue
|
||||||
alCheck(alSourceQueueBuffers(m_source, 1, &buffer));
|
alCheck(alSourceQueueBuffers(m_source, 1, &buffer));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If we get here, we most likely ran out of retries
|
||||||
|
requestStop = true;
|
||||||
|
}
|
||||||
|
|
||||||
return requestStop;
|
return requestStop;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user