Merge pull request #1325 from Sonicadvance1/Android-OpenSLES-race

Fix a race condition in our OpenSL ES audio backend.
This commit is contained in:
Ryan Houdek 2014-10-19 08:53:19 -05:00
commit b769331f50
1 changed files with 6 additions and 10 deletions

View File

@ -45,7 +45,6 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
// which for this code example would indicate a programming error
_assert_msg_(AUDIO, SL_RESULT_SUCCESS == result, "Couldn't enqueue audio stream.");
curBuffer ^= 1; // Switch buffer
// Render to the fresh buffer
g_mixer->Mix(reinterpret_cast<short *>(buffer[curBuffer]), BUFFER_SIZE_IN_SAMPLES);
@ -101,17 +100,14 @@ bool OpenSLESStream::Start()
result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
assert(SL_RESULT_SUCCESS == result);
// Render and enqueue a first buffer. (or should we just play the buffer empty?)
curBuffer = 0;
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer]));
if (SL_RESULT_SUCCESS != result)
{
return false;
}
// Render and enqueue a first buffer.
curBuffer ^= 1;
g_mixer = m_mixer;
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[0], sizeof(buffer[0]));
if (SL_RESULT_SUCCESS != result)
return false;
return true;
}