diff --git a/src/core/thread.c b/src/core/thread.c index 20cbd83cc..1642217d8 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -60,6 +60,11 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m threadContext->sync.videoFrameWait = false; MutexUnlock(&threadContext->sync.videoFrameMutex); + MutexLock(&threadContext->sync.audioBufferMutex); + bool audioWait = threadContext->sync.audioWait; + threadContext->sync.audioWait = false; + MutexUnlock(&threadContext->sync.audioBufferMutex); + while (threadContext->state == oldState) { MutexUnlock(&threadContext->stateMutex); @@ -77,6 +82,10 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m ConditionWake(&threadContext->stateCond); } + MutexLock(&threadContext->sync.audioBufferMutex); + threadContext->sync.audioWait = audioWait; + MutexUnlock(&threadContext->sync.audioBufferMutex); + MutexLock(&threadContext->sync.videoFrameMutex); threadContext->sync.videoFrameWait = videoFrameWait; MutexUnlock(&threadContext->sync.videoFrameMutex); @@ -228,8 +237,10 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) { ConditionWait(&impl->stateCond, &impl->stateMutex); if (impl->sync.audioWait) { + MutexUnlock(&impl->stateMutex); mCoreSyncLockAudio(&impl->sync); mCoreSyncProduceAudio(&impl->sync, core->getAudioChannel(core, 0), core->getAudioBufferSize(core)); + MutexLock(&impl->stateMutex); } } }