Skip to content

Commit

Permalink
Revert "faudio: Fix deadlock in voice callbacks"
Browse files Browse the repository at this point in the history
This caused some issues with streaming audio playback in FNA.

This reverts commit a623edb.
  • Loading branch information
flibitijibibo committed Apr 11, 2024
1 parent a623edb commit 6ee58c1
Showing 1 changed file with 3 additions and 63 deletions.
66 changes: 3 additions & 63 deletions src/FAudio_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,6 @@ static void FAudio_INTERNAL_DecodeBuffers(
if ( voice->src.callback != NULL &&
voice->src.callback->OnBufferStart != NULL )
{
FAudio_PlatformUnlockMutex(voice->src.bufferLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->src.bufferLock)

FAudio_PlatformUnlockMutex(voice->sendLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->sendLock)

FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)

Expand All @@ -399,12 +393,6 @@ static void FAudio_INTERNAL_DecodeBuffers(

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)

FAudio_PlatformLockMutex(voice->sendLock);
LOG_MUTEX_LOCK(voice->audio, voice->sendLock)

FAudio_PlatformLockMutex(voice->src.bufferLock);
LOG_MUTEX_LOCK(voice->audio, voice->src.bufferLock)
}
}

Expand Down Expand Up @@ -454,12 +442,6 @@ static void FAudio_INTERNAL_DecodeBuffers(
if ( voice->src.callback != NULL &&
voice->src.callback->OnLoopEnd != NULL )
{
FAudio_PlatformUnlockMutex(voice->src.bufferLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->src.bufferLock)

FAudio_PlatformUnlockMutex(voice->sendLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->sendLock)

FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)

Expand All @@ -470,12 +452,6 @@ static void FAudio_INTERNAL_DecodeBuffers(

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)

FAudio_PlatformLockMutex(voice->sendLock);
LOG_MUTEX_LOCK(voice->audio, voice->sendLock)

FAudio_PlatformLockMutex(voice->src.bufferLock);
LOG_MUTEX_LOCK(voice->audio, voice->src.bufferLock)
}
}
else
Expand Down Expand Up @@ -528,12 +504,6 @@ static void FAudio_INTERNAL_DecodeBuffers(
/* Callbacks */
if (voice->src.callback != NULL)
{
FAudio_PlatformUnlockMutex(voice->src.bufferLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->src.bufferLock)

FAudio_PlatformUnlockMutex(voice->sendLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->sendLock)

FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)

Expand All @@ -552,15 +522,6 @@ static void FAudio_INTERNAL_DecodeBuffers(
);
}

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)

FAudio_PlatformLockMutex(voice->sendLock);
LOG_MUTEX_LOCK(voice->audio, voice->sendLock)

FAudio_PlatformLockMutex(voice->src.bufferLock);
LOG_MUTEX_LOCK(voice->audio, voice->src.bufferLock)

/* One last chance at redemption */
if (buffer == NULL && voice->src.bufferList != NULL)
{
Expand All @@ -570,29 +531,14 @@ static void FAudio_INTERNAL_DecodeBuffers(

if (buffer != NULL && voice->src.callback->OnBufferStart != NULL)
{
FAudio_PlatformUnlockMutex(voice->src.bufferLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->src.bufferLock)

FAudio_PlatformUnlockMutex(voice->sendLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->sendLock)

FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)

voice->src.callback->OnBufferStart(
voice->src.callback,
buffer->pContext
);

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)

FAudio_PlatformLockMutex(voice->sendLock);
LOG_MUTEX_LOCK(voice->audio, voice->sendLock)

FAudio_PlatformLockMutex(voice->src.bufferLock);
LOG_MUTEX_LOCK(voice->audio, voice->src.bufferLock)
}

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)
}

voice->audio->pFree(toDelete);
Expand Down Expand Up @@ -1304,9 +1250,6 @@ static void FAudio_INTERNAL_FlushPendingBuffers(FAudioSourceVoice *voice)

if (voice->src.callback != NULL && voice->src.callback->OnBufferEnd != NULL)
{
FAudio_PlatformUnlockMutex(voice->src.bufferLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->src.bufferLock)

FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)

Expand All @@ -1317,9 +1260,6 @@ static void FAudio_INTERNAL_FlushPendingBuffers(FAudioSourceVoice *voice)

FAudio_PlatformLockMutex(voice->audio->sourceLock);
LOG_MUTEX_LOCK(voice->audio, voice->audio->sourceLock)

FAudio_PlatformLockMutex(voice->src.bufferLock);
LOG_MUTEX_LOCK(voice->audio, voice->src.bufferLock)
}
voice->audio->pFree(entry);
}
Expand Down

0 comments on commit 6ee58c1

Please sign in to comment.