From a1a084aabb9b36ab002002274eab345f446c68db Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 25 Jun 2022 05:12:43 -0700 Subject: [PATCH] [Audio Output] Fix serious deadlock issue There was a serious deadlock issue. Now it is fixed. Whew. Signed-off-by: Christopher Snowhill --- Audio/AudioPlayer.m | 2 ++ Audio/Chain/OutputNode.m | 4 ---- Audio/Output/OutputAVFoundation.m | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index c720bf783..2ce5558cd 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -62,6 +62,7 @@ [self waitUntilCallbacksExit]; if(output) { [output setShouldContinue:NO]; + [output close]; } if(!output) { output = [[OutputNode alloc] initWithController:self previous:nil]; @@ -136,6 +137,7 @@ } if(output) { [output setShouldContinue:NO]; + [output close]; } output = nil; } diff --git a/Audio/Chain/OutputNode.m b/Audio/Chain/OutputNode.m index c03d82d32..dc128bb8f 100644 --- a/Audio/Chain/OutputNode.m +++ b/Audio/Chain/OutputNode.m @@ -156,10 +156,6 @@ } - (void)setShouldContinue:(BOOL)s { - if(output && !s) { - [output stop]; - } - [super setShouldContinue:s]; // if (s == NO) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index b0fb55a80..d6b3b2621 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -301,7 +301,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons } - (BOOL)signalEndOfStream:(double)latency { + stopped = YES; BOOL ret = [outputController selectNextBuffer]; + stopped = ret; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC * latency)), dispatch_get_main_queue(), ^{ [self->outputController endOfInputPlayed]; [self->outputController resetAmountPlayed]; @@ -1009,9 +1011,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons - (void)doStop { if(stopInvoked) { - while(!stopCompleted) { - usleep(5000); - } + stopFlush = NO; return; } @synchronized(self) { @@ -1060,7 +1060,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons compareVal = CMTimeCompare(outputPts, currentPts); [currentPtsLock unlock]; usleep(5000); - } while(compareVal > 0); + } while(stopFlush && compareVal > 0); } [self removeSynchronizerBlock]; [renderSynchronizer setRate:0];