From cb2ce5675a1ca60e44ab91ed33febe601164e7d3 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 25 Jun 2022 02:36:14 -0700 Subject: [PATCH] [FFmpeg] Fix chapter handling and seeking Fix chapter startup, and chapter seeking. Signed-off-by: Christopher Snowhill --- Plugins/FFMPEG/FFMPEGDecoder.h | 1 + Plugins/FFMPEG/FFMPEGDecoder.m | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Plugins/FFMPEG/FFMPEGDecoder.h b/Plugins/FFMPEG/FFMPEGDecoder.h index 6f9da3fba..e6100ccd4 100644 --- a/Plugins/FFMPEG/FFMPEGDecoder.h +++ b/Plugins/FFMPEG/FFMPEGDecoder.h @@ -32,6 +32,7 @@ int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence); int subsong; int64_t startTime; int64_t endTime; + BOOL seekedToStart; @private unsigned char *buffer; diff --git a/Plugins/FFMPEG/FFMPEGDecoder.m b/Plugins/FFMPEG/FFMPEGDecoder.m index ca006c1d4..1e03c72ee 100644 --- a/Plugins/FFMPEG/FFMPEGDecoder.m +++ b/Plugins/FFMPEG/FFMPEGDecoder.m @@ -463,6 +463,8 @@ static uint8_t reverse_bits[0x100]; seekable = [s seekable]; + seekedToStart = !seekable; + artist = @""; albumartist = @""; album = @""; @@ -684,6 +686,10 @@ static uint8_t reverse_bits[0x100]; } - (int)readAudio:(void *)buf frames:(UInt32)frames { + if(!seekedToStart) { + [self seek:0]; + } + int frameSize = rawDSD ? channels : channels * (bitsPerSample / 8); int bytesToRead = frames * frameSize; int bytesRead = 0; @@ -914,6 +920,8 @@ static uint8_t reverse_bits[0x100]; if(!totalFrames) return -1; + seekedToStart = YES; + prebufferedAudio = 0; if(frame >= totalFrames) {