ALStream: Actually fix issue referenced in prev commit

This bug occured when starting playback of a stream, then immediately
stopping it, loading a different source, and starting playback again.

The real issue was that in stopStream(),  the streaming thread had
not even queued anything yet, so it first decoded some data, then
started playing the source (which had already been stopped in the main
thread), and then finally saw the term request and stopped.

Instead stopping the source after the thread has definitely
terminated fixed the problem.
This commit is contained in:
Jonas Kulla 2014-07-31 05:12:35 +02:00
parent 80937d0d06
commit 818ca18ebb
1 changed files with 11 additions and 2 deletions

View File

@ -213,8 +213,6 @@ void ALStream::stopStream()
{ {
threadTermReq = true; threadTermReq = true;
AL::Source::stop(alSrc);
if (thread) if (thread)
{ {
SDL_WaitThread(thread, 0); SDL_WaitThread(thread, 0);
@ -222,6 +220,11 @@ void ALStream::stopStream()
needsRewind = true; needsRewind = true;
} }
/* Need to stop the source _after_ the thread has terminated,
* because it might have accidentally started it again before
* seeing the term request */
AL::Source::stop(alSrc);
procFrames = 0; procFrames = 0;
} }
@ -298,6 +301,9 @@ void ALStream::streamData()
bool firstBuffer = true; bool firstBuffer = true;
ALDataSource::Status status; ALDataSource::Status status;
if (threadTermReq)
return;
if (needsRewind) if (needsRewind)
{ {
if (startOffset > 0) if (startOffset > 0)
@ -308,6 +314,9 @@ void ALStream::streamData()
for (int i = 0; i < STREAM_BUFS; ++i) for (int i = 0; i < STREAM_BUFS; ++i)
{ {
if (threadTermReq)
return;
AL::Buffer::ID buf = alBuf[i]; AL::Buffer::ID buf = alBuf[i];
status = source->fillBuffer(buf); status = source->fillBuffer(buf);