Restart playback on device or output format change

Now the output is restarted on the current file at the current position
if the output format has changed. This should resolve the issue finally.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-02-07 22:44:56 -08:00
parent 728c44242c
commit f4f4f80f64
9 changed files with 43 additions and 1 deletions

View File

@ -756,6 +756,12 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
[miniWindow showHDCDLogo:YES];
}
- (void)audioPlayer:(AudioPlayer *)player restartPlaybackAtCurrentPosition:(id)userInfo {
PlaylistEntry *pe = [playlistController currentEntry];
BOOL paused = playbackStatus == CogStatusPaused;
[player play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused andSeekTo:[pe currentPosition]];
}
- (void)removeHDCD:(id)sender {
MainWindow *mainWindow = (MainWindow *)appController.mainWindow;
[mainWindow showHDCDLogo:NO];

View File

@ -76,6 +76,8 @@
- (void)setNextStream:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi;
- (void)resetNextStreams;
- (void)restartPlaybackAtCurrentPosition;
+ (NSArray *)fileTypes;
+ (NSArray *)schemes;
+ (NSArray *)containerTypes;
@ -121,5 +123,5 @@
- (void)audioPlayer:(AudioPlayer *)player refreshEqualizer:(AudioUnit)eq;
- (void)audioPlayer:(AudioPlayer *)player removeEqualizer:(AudioUnit)eq;
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo;
- (void)audioPlayer:(AudioPlayer *)player restartPlaybackAtCurrentPosition:(id)userInfo;
@end

View File

@ -220,6 +220,10 @@
}
}
- (void)restartPlaybackAtCurrentPosition {
[self sendDelegateMethod:@selector(audioPlayer:restartPlaybackAtCurrentPosition:) withObject:[bufferChain userInfo] waitUntilDone:NO];
}
- (void)setShouldContinue:(BOOL)s {
shouldContinue = s;

View File

@ -75,4 +75,6 @@
- (void)sustainHDCD;
- (void)restartPlaybackAtCurrentPosition;
@end

View File

@ -260,4 +260,8 @@
[controller sustainHDCD];
}
- (void)restartPlaybackAtCurrentPosition {
[controller restartPlaybackAtCurrentPosition];
}
@end

View File

@ -63,4 +63,6 @@
- (void)sustainHDCD;
- (void)restartPlaybackAtCurrentPosition;
@end

View File

@ -159,4 +159,8 @@
[output sustainHDCD];
}
- (void)restartPlaybackAtCurrentPosition {
[controller restartPlaybackAtCurrentPosition];
}
@end

View File

@ -41,6 +41,7 @@
BOOL started;
BOOL paused;
BOOL stopNext;
BOOL restarted;
BOOL eqEnabled;

View File

@ -167,6 +167,7 @@ static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioAct
running = NO;
started = NO;
stopNext = NO;
restarted = NO;
streamFormatStarted = NO;
@ -211,10 +212,16 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
running = YES;
started = NO;
stopNext = NO;
size_t eventCount = 0;
atomic_store(&bytesRendered, 0);
NSMutableArray *delayedEvents = [[NSMutableArray alloc] init];
BOOL delayedEventsPopped = YES;
while(!stopping) {
if(++eventCount == 48) {
[self resetIfOutputChanged];
if(restarted) break;
eventCount = 0;
}
if([outputController shouldReset]) {
@autoreleasepool {
[[outputController buffer] reset];
@ -459,6 +466,15 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
free(devids);
}
- (void)resetIfOutputChanged {
AVAudioFormat *format = _au.outputBusses[0].format;
if(!restarted && !_deviceFormat || ![_deviceFormat isEqual:format]) {
[outputController restartPlaybackAtCurrentPosition];
restarted = YES;
}
}
- (BOOL)updateDeviceFormat {
AVAudioFormat *format = _au.outputBusses[0].format;
@ -560,6 +576,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
paused = NO;
stopNext = NO;
outputDeviceID = -1;
restarted = NO;
downmixer = nil;