From 0cc084b58bb438a98885cf420db2ecfc096cfa2d Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 24 Jun 2022 03:46:01 -0700 Subject: [PATCH] [Audio Output] Properly handle end of playlist Handle audio on the end of the playlist, flushing playback until all output stops. Signed-off-by: Christopher Snowhill --- Audio/Output/OutputAVFoundation.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index f54289078..d3c7c67e8 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -317,6 +317,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons - (BOOL)processEndOfStream { if([outputController endOfStream] == YES && [self signalEndOfStream:secondsLatency]) { stopping = YES; + stopFlush = YES; return YES; } return NO; @@ -326,6 +327,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons running = YES; started = NO; secondsLatency = 1.0; + stopFlush = NO; while(!stopping) { if([outputController shouldReset]) { @@ -358,8 +360,8 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons [audioRenderer enqueueSampleBuffer:bufferRef]; } else { + stopFlush = YES; break; - // r8b will absorb some samples first } } @@ -375,7 +377,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons } stopped = YES; - [self stop]; + if(!stopInvoked) { + [self stop]; + } } - (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID { @@ -1033,7 +1037,17 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons } if(renderSynchronizer || audioRenderer) { if(renderSynchronizer) { + if(stopFlush) { + int compareVal = 0; + do { + [currentPtsLock lock]; + compareVal = CMTimeCompare(outputPts, currentPts); + [currentPtsLock unlock]; + usleep(5000); + } while(compareVal > 0); + } [self removeSynchronizerBlock]; + [renderSynchronizer setRate:0]; } if(audioRenderer) { [audioRenderer stopRequestingMediaData];