mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +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,22 +399,28 @@ 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)
|
||||||
{
|
{
|
||||||
|
// Not looping: request stop
|
||||||
|
requestStop = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Return to the beginning of the stream source
|
// Return to the beginning of the stream source
|
||||||
onSeek(Time::Zero);
|
onSeek(Time::Zero);
|
||||||
|
|
||||||
// If we previously had no data, try to fill the buffer once again
|
// If we got data, break and process it, else try to fill the buffer once again
|
||||||
if (!data.samples || (data.sampleCount == 0))
|
if (data.samples && data.sampleCount)
|
||||||
{
|
break;
|
||||||
|
|
||||||
// If immediateLoop is specified, we have to immediately adjust the sample count
|
// If immediateLoop is specified, we have to immediately adjust the sample count
|
||||||
if (immediateLoop)
|
if (immediateLoop)
|
||||||
{
|
{
|
||||||
@ -422,14 +428,8 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
|
|||||||
m_samplesProcessed = 0;
|
m_samplesProcessed = 0;
|
||||||
m_endBuffers[bufferNum] = false;
|
m_endBuffers[bufferNum] = false;
|
||||||
}
|
}
|
||||||
return fillAndPushBuffer(bufferNum);
|
|
||||||
}
|
// We're a looping sound that got no data, so we retry onGetData()
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Not looping: request stop
|
|
||||||
requestStop = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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