Fixed audio thread may set the state to playing even in certain conditions even if the player has been user-paused or stopped (race condition)

This commit is contained in:
Thong Nguyen 2014-02-05 19:05:47 +00:00
parent ce6f2b9512
commit a15405b6c5
1 changed files with 22 additions and 7 deletions

View File

@ -1533,8 +1533,6 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn
if (audioGraph != nil)
{
//error = AudioOutputUnitStart(outputAudiotUnit);
error = AUGraphStart(audioGraph);
if (error)
@ -1907,6 +1905,15 @@ static BOOL GetHardwareCodecClassDesc(UInt32 formatId, AudioClassDescription* cl
OSStatus status;
[self resetPcmBuffers];
Boolean isRunning;
status = AUGraphIsRunning(audioGraph, &isRunning);
if (isRunning)
{
return NO;
}
status = AUGraphStart(audioGraph);
@ -1932,6 +1939,15 @@ static BOOL GetHardwareCodecClassDesc(UInt32 formatId, AudioClassDescription* cl
return;
}
Boolean isRunning;
status = AUGraphIsRunning(audioGraph, &isRunning);
if (!isRunning)
{
return;
}
status = AUGraphStop(audioGraph);
[self resetPcmBuffers];
@ -2369,8 +2385,6 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags*
{
return (state & STKAudioPlayerInternalStateRunning) && state != STKAudioPlayerInternalStatePaused;
}];
audioPlayer.internalState = STKAudioPlayerInternalStatePlaying;
}
if (totalFramesCopied < inNumberFrames)
@ -2383,9 +2397,10 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags*
{
// Buffering
pthread_mutex_lock(&audioPlayer->playerMutex);
audioPlayer.internalState = STKAudioPlayerInternalStateRebuffering;
pthread_mutex_unlock(&audioPlayer->playerMutex);
[audioPlayer setInternalState:STKAudioPlayerInternalStateRebuffering ifInState:^BOOL(STKAudioPlayerInternalState state)
{
return (state & STKAudioPlayerInternalStateRunning) && state != STKAudioPlayerInternalStatePaused;
}];
}
}