[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 <kode54@gmail.com>
lastfm
Christopher Snowhill 2022-06-24 03:46:01 -07:00
parent 858f446597
commit 0cc084b58b
1 changed files with 16 additions and 2 deletions

View File

@ -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];