mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-25 03:32:01 +00:00
Attempted to resolve risk of an audio callback being in progress when -dealloc is received.
This commit is contained in:
parent
6120dae61a
commit
4c947ad553
@ -12,6 +12,8 @@
|
||||
#define AudioQueueBufferMaxLength 8192
|
||||
#define NumberOfStoredAudioQueueBuffer 16
|
||||
|
||||
static NSLock *CSAudioQueueDeallocLock;
|
||||
|
||||
@implementation CSAudioQueue
|
||||
{
|
||||
AudioQueueRef _audioQueue;
|
||||
@ -45,7 +47,11 @@ static void audioOutputCallback(
|
||||
AudioQueueRef inAQ,
|
||||
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
|
||||
@ -56,6 +62,11 @@ static void audioOutputCallback(
|
||||
|
||||
if(self)
|
||||
{
|
||||
if(!CSAudioQueueDeallocLock)
|
||||
{
|
||||
CSAudioQueueDeallocLock = [[NSLock alloc] init];
|
||||
}
|
||||
|
||||
_samplingRate = samplingRate;
|
||||
|
||||
// determine preferred buffer sizes
|
||||
@ -104,7 +115,9 @@ static void audioOutputCallback(
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if(_audioQueue) AudioQueueDispose(_audioQueue, YES);
|
||||
[CSAudioQueueDeallocLock lock];
|
||||
if(_audioQueue) AudioQueueDispose(_audioQueue, true);
|
||||
[CSAudioQueueDeallocLock unlock];
|
||||
}
|
||||
|
||||
#pragma mark - Audio enqueuer
|
||||
|
Loading…
Reference in New Issue
Block a user