1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Attempted to resolve risk of an audio callback being in progress when -dealloc is received.

This commit is contained in:
Thomas Harte 2017-02-22 21:12:59 -05:00
parent 6120dae61a
commit 4c947ad553

View File

@ -12,6 +12,8 @@
#define AudioQueueBufferMaxLength 8192 #define AudioQueueBufferMaxLength 8192
#define NumberOfStoredAudioQueueBuffer 16 #define NumberOfStoredAudioQueueBuffer 16
static NSLock *CSAudioQueueDeallocLock;
@implementation CSAudioQueue @implementation CSAudioQueue
{ {
AudioQueueRef _audioQueue; AudioQueueRef _audioQueue;
@ -45,7 +47,11 @@ static void audioOutputCallback(
AudioQueueRef inAQ, AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer) AudioQueueBufferRef inBuffer)
{ {
[(__bridge CSAudioQueue *)inUserData audioQueue:inAQ didCallbackWithBuffer:inBuffer]; if([CSAudioQueueDeallocLock tryLock])
{
[(__bridge CSAudioQueue *)inUserData audioQueue:inAQ didCallbackWithBuffer:inBuffer];
[CSAudioQueueDeallocLock unlock];
}
} }
#pragma mark - Standard object lifecycle #pragma mark - Standard object lifecycle
@ -56,6 +62,11 @@ static void audioOutputCallback(
if(self) if(self)
{ {
if(!CSAudioQueueDeallocLock)
{
CSAudioQueueDeallocLock = [[NSLock alloc] init];
}
_samplingRate = samplingRate; _samplingRate = samplingRate;
// determine preferred buffer sizes // determine preferred buffer sizes
@ -104,7 +115,9 @@ static void audioOutputCallback(
- (void)dealloc - (void)dealloc
{ {
if(_audioQueue) AudioQueueDispose(_audioQueue, YES); [CSAudioQueueDeallocLock lock];
if(_audioQueue) AudioQueueDispose(_audioQueue, true);
[CSAudioQueueDeallocLock unlock];
} }
#pragma mark - Audio enqueuer #pragma mark - Audio enqueuer