From 3fcf054a23f25a6bbda993f7bf807c880f23a1b7 Mon Sep 17 00:00:00 2001 From: Thong Nguyen Date: Mon, 7 Apr 2014 15:15:36 +0100 Subject: [PATCH] Fix STKAudioPlayer.progress property thread-related crash --- StreamingKit/StreamingKit/STKAudioPlayer.m | 16 +++++++++------- StreamingKit/StreamingKit/STKQueueEntry.m | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index adc8663..7e3a4e4 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -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) { diff --git a/StreamingKit/StreamingKit/STKQueueEntry.m b/StreamingKit/StreamingKit/STKQueueEntry.m index 1e27973..2b6de04 100644 --- a/StreamingKit/StreamingKit/STKQueueEntry.m +++ b/StreamingKit/StreamingKit/STKQueueEntry.m @@ -18,6 +18,8 @@ { if (self = [super init]) { + self->spinLock = OS_SPINLOCK_INIT; + self.dataSource = dataSourceIn; self.queueItemId = queueItemIdIn; self->lastFrameQueued = -1;