[Cuesheet] Greatly improve loading performance

Cuesheets were invoking a seek operation on open, rather than on first
playback, and this has a heavy toll on FFmpeg audio formats, apparently.
Defer the initial seek to the first readAudio call, and do not invoke it
if a seek was already called on that input session.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
lastfm
Christopher Snowhill 2022-06-25 02:38:17 -07:00
parent b3be8f9d11
commit ed8c8acc89
2 changed files with 11 additions and 3 deletions

View File

@ -19,6 +19,8 @@
NSURL *sourceURL;
BOOL seekedToStart;
int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8)
long framePosition; // Current position in frames.

View File

@ -154,7 +154,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
}
[self seek:0];
seekedToStart = NO;
// Note: Should register for observations of the decoder
[self willChangeValueForKey:@"properties"];
@ -192,7 +192,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
[self seek:0];
seekedToStart = NO;
return YES;
}
@ -297,7 +297,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
trackEnd = [[[decoder properties] objectForKey:@"totalFrames"] longValue];
}
[self seek:0];
seekedToStart = NO;
DLog(@"CHANGING TRACK!");
return YES;
@ -314,6 +314,8 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
return -1;
}
seekedToStart = YES;
frame += trackStart;
framePosition = [decoder seek:frame];
@ -322,6 +324,10 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
}
- (int)readAudio:(void *)buf frames:(UInt32)frames {
if(!seekedToStart) {
[self seek:0];
}
if(!noFragment && framePosition + frames > trackEnd) {
frames = (UInt32)(trackEnd - framePosition);
}