1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 18:30:21 +00:00

Switched away from @synchronized as it appears possibly to be the lock used during -dealloc, creating deadlock with the CSAudioQueueDeallocLock.

This commit is contained in:
Thomas Harte 2017-02-22 21:42:10 -05:00
parent 8291a63d5f
commit 2f0c923c29

View File

@ -17,8 +17,8 @@ static NSLock *CSAudioQueueDeallocLock;
@implementation CSAudioQueue @implementation CSAudioQueue
{ {
AudioQueueRef _audioQueue; AudioQueueRef _audioQueue;
AudioQueueBufferRef _storedBuffers[NumberOfStoredAudioQueueBuffer]; AudioQueueBufferRef _storedBuffers[NumberOfStoredAudioQueueBuffer];
NSLock *_storedBuffersLock;
} }
#pragma mark - AudioQueue callbacks #pragma mark - AudioQueue callbacks
@ -27,18 +27,18 @@ static NSLock *CSAudioQueueDeallocLock;
{ {
[self.delegate audioQueueIsRunningDry:self]; [self.delegate audioQueueIsRunningDry:self];
@synchronized(self) [_storedBuffersLock lock];
{
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++) for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++)
{ {
if(!_storedBuffers[c] || buffer->mAudioDataBytesCapacity > _storedBuffers[c]->mAudioDataBytesCapacity) if(!_storedBuffers[c] || buffer->mAudioDataBytesCapacity > _storedBuffers[c]->mAudioDataBytesCapacity)
{ {
if(_storedBuffers[c]) AudioQueueFreeBuffer(_audioQueue, _storedBuffers[c]); if(_storedBuffers[c]) AudioQueueFreeBuffer(_audioQueue, _storedBuffers[c]);
_storedBuffers[c] = buffer; _storedBuffers[c] = buffer;
[_storedBuffersLock unlock];
return; return;
} }
} }
} [_storedBuffersLock unlock];
AudioQueueFreeBuffer(_audioQueue, buffer); AudioQueueFreeBuffer(_audioQueue, buffer);
} }
@ -66,6 +66,7 @@ static void audioOutputCallback(
{ {
CSAudioQueueDeallocLock = [[NSLock alloc] init]; CSAudioQueueDeallocLock = [[NSLock alloc] init];
} }
_storedBuffersLock = [[NSLock alloc] init];
_samplingRate = samplingRate; _samplingRate = samplingRate;
@ -126,8 +127,7 @@ static void audioOutputCallback(
{ {
size_t bufferBytes = lengthInSamples * sizeof(int16_t); size_t bufferBytes = lengthInSamples * sizeof(int16_t);
@synchronized(self) [_storedBuffersLock lock];
{
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++) for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++)
{ {
if(_storedBuffers[c] && _storedBuffers[c]->mAudioDataBytesCapacity >= bufferBytes) if(_storedBuffers[c] && _storedBuffers[c]->mAudioDataBytesCapacity >= bufferBytes)
@ -137,9 +137,11 @@ static void audioOutputCallback(
AudioQueueEnqueueBuffer(_audioQueue, _storedBuffers[c], 0, NULL); AudioQueueEnqueueBuffer(_audioQueue, _storedBuffers[c], 0, NULL);
_storedBuffers[c] = NULL; _storedBuffers[c] = NULL;
[_storedBuffersLock unlock];
return; return;
} }
} }
[_storedBuffersLock unlock];
AudioQueueBufferRef newBuffer; AudioQueueBufferRef newBuffer;
AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes * 2, &newBuffer); AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes * 2, &newBuffer);
@ -148,7 +150,6 @@ static void audioOutputCallback(
AudioQueueEnqueueBuffer(_audioQueue, newBuffer, 0, NULL); AudioQueueEnqueueBuffer(_audioQueue, newBuffer, 0, NULL);
} }
}
#pragma mark - Sampling Rate getters #pragma mark - Sampling Rate getters