Skip to content

Commit

Permalink
Fix deadlock by not checking for isRunning and stopping unit in callb…
Browse files Browse the repository at this point in the history
…ack.
  • Loading branch information
hannseman committed Oct 3, 2016
1 parent d988718 commit 71d68c3
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions LFLiveKit/capture/LFAudioCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ - (void)dealloc {

dispatch_sync(self.taskQueue, ^{
if (self.componetInstance) {
self.isRunning = NO;
AudioOutputUnitStop(self.componetInstance);
AudioComponentInstanceDispose(self.componetInstance);
self.componetInstance = nil;
Expand All @@ -120,7 +121,11 @@ - (void)setRunning:(BOOL)running {
AudioOutputUnitStart(self.componetInstance);
});
} else {
self.isRunning = NO;
dispatch_sync(self.taskQueue, ^{
self.isRunning = NO;
NSLog(@"MicrophoneSource: stopRunning");
AudioOutputUnitStop(self.componetInstance);
});
}
}

Expand Down Expand Up @@ -191,7 +196,7 @@ - (void)handleInterruption:(NSNotification *)notification {
case AVAudioSessionInterruptionOptionShouldResume:
if (self.isRunning) {
dispatch_async(self.taskQueue, ^{
NSLog(@"MicrophoneSource: stopRunning");
NSLog(@"MicrophoneSource: startRunning");
AudioOutputUnitStart(self.componetInstance);
});
}
Expand Down Expand Up @@ -234,15 +239,6 @@ static OSStatus handleInputBuffer(void *inRefCon,
inNumberFrames,
&buffers);

if (!source.isRunning) {
dispatch_sync(source.taskQueue, ^{
NSLog(@"MicrophoneSource: stopRunning");
AudioOutputUnitStop(source.componetInstance);
});

return status;
}

if (source.muted) {
for (int i = 0; i < buffers.mNumberBuffers; i++) {
AudioBuffer ab = buffers.mBuffers[i];
Expand Down

0 comments on commit 71d68c3

Please sign in to comment.