mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-30 04:50:08 +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;
|
||||
@ -44,8 +46,12 @@ static void audioOutputCallback(
|
||||
void *inUserData,
|
||||
AudioQueueRef inAQ,
|
||||
AudioQueueBufferRef 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