1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +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
{
AudioQueueRef _audioQueue;
AudioQueueBufferRef _storedBuffers[NumberOfStoredAudioQueueBuffer];
NSLock *_storedBuffersLock;
}
#pragma mark - AudioQueue callbacks
@ -27,18 +27,18 @@ static NSLock *CSAudioQueueDeallocLock;
{
[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]);
_storedBuffers[c] = buffer;
return;
}
if(_storedBuffers[c]) AudioQueueFreeBuffer(_audioQueue, _storedBuffers[c]);
_storedBuffers[c] = buffer;
[_storedBuffersLock unlock];
return;
}
}
[_storedBuffersLock unlock];
AudioQueueFreeBuffer(_audioQueue, buffer);
}
@ -66,6 +66,7 @@ static void audioOutputCallback(
{
CSAudioQueueDeallocLock = [[NSLock alloc] init];
}
_storedBuffersLock = [[NSLock alloc] init];
_samplingRate = samplingRate;
@ -126,28 +127,28 @@ static void audioOutputCallback(
{
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)
{
memcpy(_storedBuffers[c]->mAudioData, buffer, bufferBytes);
_storedBuffers[c]->mAudioDataByteSize = (UInt32)bufferBytes;
memcpy(_storedBuffers[c]->mAudioData, buffer, bufferBytes);
_storedBuffers[c]->mAudioDataByteSize = (UInt32)bufferBytes;
AudioQueueEnqueueBuffer(_audioQueue, _storedBuffers[c], 0, NULL);
_storedBuffers[c] = NULL;
return;
}
AudioQueueEnqueueBuffer(_audioQueue, _storedBuffers[c], 0, NULL);
_storedBuffers[c] = NULL;
[_storedBuffersLock unlock];
return;
}
AudioQueueBufferRef newBuffer;
AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes * 2, &newBuffer);
memcpy(newBuffer->mAudioData, buffer, bufferBytes);
newBuffer->mAudioDataByteSize = (UInt32)bufferBytes;
AudioQueueEnqueueBuffer(_audioQueue, newBuffer, 0, NULL);
}
[_storedBuffersLock unlock];
AudioQueueBufferRef newBuffer;
AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes * 2, &newBuffer);
memcpy(newBuffer->mAudioData, buffer, bufferBytes);
newBuffer->mAudioDataByteSize = (UInt32)bufferBytes;
AudioQueueEnqueueBuffer(_audioQueue, newBuffer, 0, NULL);
}
#pragma mark - Sampling Rate getters