|
|
|
@@ -530,7 +530,12 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn
|
|
|
|
|
{
|
|
|
|
|
currentlyPlayingEntry.dataSource.delegate = nil;
|
|
|
|
|
[currentlyReadingEntry.dataSource unregisterForEvents];
|
|
|
|
|
|
|
|
|
|
OSSpinLockLock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
currentlyPlayingEntry = nil;
|
|
|
|
|
|
|
|
|
|
OSSpinLockUnlock(¤tEntryReferencesLock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self stopAudioUnitWithReason:STKAudioPlayerStopReasonDisposed];
|
|
|
|
@@ -928,20 +933,15 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OSSpinLockLock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
STKQueueEntry* entry = currentlyPlayingEntry;
|
|
|
|
|
OSSpinLockUnlock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
if (entry == nil)
|
|
|
|
|
{
|
|
|
|
|
OSSpinLockUnlock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double retval = [entry duration];
|
|
|
|
|
|
|
|
|
|
OSSpinLockUnlock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
double progress = [self progress];
|
|
|
|
|
|
|
|
|
|
if (retval < progress && retval > 0)
|
|
|
|
@@ -964,7 +964,9 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OSSpinLockLock(¤tEntryReferencesLock);
|
|
|
|
|
STKQueueEntry* entry = currentlyPlayingEntry;
|
|
|
|
|
OSSpinLockUnlock(¤tEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
if (entry == nil)
|
|
|
|
|
{
|
|
|
|
@@ -2535,11 +2537,15 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags*
|
|
|
|
|
{
|
|
|
|
|
STKAudioPlayer* audioPlayer = (__bridge STKAudioPlayer*)inRefCon;
|
|
|
|
|
|
|
|
|
|
OSSpinLockLock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
STKQueueEntry* entry = audioPlayer->currentlyPlayingEntry;
|
|
|
|
|
STKQueueEntry* currentlyReadingEntry = audioPlayer->currentlyReadingEntry;
|
|
|
|
|
OSSpinLockUnlock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
OSSpinLockLock(&audioPlayer->pcmBufferSpinLock);
|
|
|
|
|
|
|
|
|
|
BOOL waitForBuffer = NO;
|
|
|
|
|
BOOL muted = audioPlayer->muted;
|
|
|
|
|
STKQueueEntry* entry = audioPlayer->currentlyPlayingEntry;
|
|
|
|
|
AudioBuffer* audioBuffer = audioPlayer->pcmAudioBuffer;
|
|
|
|
|
UInt32 frameSizeInBytes = audioPlayer->pcmBufferFrameSizeInBytes;
|
|
|
|
|
UInt32 used = audioPlayer->pcmBufferUsedFrameCount;
|
|
|
|
@@ -2557,10 +2563,10 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags*
|
|
|
|
|
|
|
|
|
|
if (entry->lastFrameQueued >= 0)
|
|
|
|
|
{
|
|
|
|
|
framesRequiredToStartPlaying = MIN(framesRequiredToStartPlaying, audioPlayer->currentlyPlayingEntry->lastFrameQueued);
|
|
|
|
|
framesRequiredToStartPlaying = MIN(framesRequiredToStartPlaying, entry->lastFrameQueued);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entry && audioPlayer->currentlyReadingEntry == entry
|
|
|
|
|
if (entry && currentlyReadingEntry == entry
|
|
|
|
|
&& entry->framesQueued < framesRequiredToStartPlaying)
|
|
|
|
|
{
|
|
|
|
|
waitForBuffer = YES;
|
|
|
|
@@ -2770,13 +2776,19 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags*
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_lock(&audioPlayer->playerMutex);
|
|
|
|
|
|
|
|
|
|
if (lastFramePlayed && entry == audioPlayer->currentlyPlayingEntry)
|
|
|
|
|
OSSpinLockLock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
STKQueueEntry* currentlyPlayingEntry = audioPlayer->currentlyPlayingEntry;
|
|
|
|
|
OSSpinLockUnlock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
if (lastFramePlayed && entry == currentlyPlayingEntry)
|
|
|
|
|
{
|
|
|
|
|
[audioPlayer audioQueueFinishedPlaying:entry];
|
|
|
|
|
|
|
|
|
|
while (extraFramesPlayedNotAssigned > 0)
|
|
|
|
|
{
|
|
|
|
|
OSSpinLockLock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
STKQueueEntry* newEntry = audioPlayer->currentlyPlayingEntry;
|
|
|
|
|
OSSpinLockUnlock(&audioPlayer->currentEntryReferencesLock);
|
|
|
|
|
|
|
|
|
|
if (newEntry != nil)
|
|
|
|
|
{
|
|
|
|
|