[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>swiftingly
parent
cb2ce5675a
commit
0f923e6072
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
NSURL *sourceURL;
|
NSURL *sourceURL;
|
||||||
|
|
||||||
|
BOOL seekedToStart;
|
||||||
|
|
||||||
int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8)
|
int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8)
|
||||||
|
|
||||||
long framePosition; // Current position in frames.
|
long framePosition; // Current position in frames.
|
||||||
|
|
|
@ -154,7 +154,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
|
||||||
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
|
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self seek:0];
|
seekedToStart = NO;
|
||||||
|
|
||||||
// Note: Should register for observations of the decoder
|
// Note: Should register for observations of the decoder
|
||||||
[self willChangeValueForKey:@"properties"];
|
[self willChangeValueForKey:@"properties"];
|
||||||
|
@ -192,7 +192,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
|
||||||
|
|
||||||
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
|
trackEnd = [[properties objectForKey:@"totalFrames"] doubleValue];
|
||||||
|
|
||||||
[self seek:0];
|
seekedToStart = NO;
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
|
||||||
trackEnd = [[[decoder properties] objectForKey:@"totalFrames"] longValue];
|
trackEnd = [[[decoder properties] objectForKey:@"totalFrames"] longValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self seek:0];
|
seekedToStart = NO;
|
||||||
|
|
||||||
DLog(@"CHANGING TRACK!");
|
DLog(@"CHANGING TRACK!");
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -314,6 +314,8 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seekedToStart = YES;
|
||||||
|
|
||||||
frame += trackStart;
|
frame += trackStart;
|
||||||
|
|
||||||
framePosition = [decoder seek:frame];
|
framePosition = [decoder seek:frame];
|
||||||
|
@ -322,6 +324,10 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)readAudio:(void *)buf frames:(UInt32)frames {
|
- (int)readAudio:(void *)buf frames:(UInt32)frames {
|
||||||
|
if(!seekedToStart) {
|
||||||
|
[self seek:0];
|
||||||
|
}
|
||||||
|
|
||||||
if(!noFragment && framePosition + frames > trackEnd) {
|
if(!noFragment && framePosition + frames > trackEnd) {
|
||||||
frames = (UInt32)(trackEnd - framePosition);
|
frames = (UInt32)(trackEnd - framePosition);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue