From b53567edc559698b7736f0692717723425e11f97 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 27 Jan 2022 00:09:40 -0800 Subject: [PATCH] Fix VGMStream so it handles EOF properly The file prober in FFmpeg expects that when the read function reaches end of file, it returns AVERROR_EOF, not zero. Otherwise, it will loop endlessly until the process is terminated. Fixes #217. Signed-off-by: Christopher Snowhill --- .../vgmstream/vgmstream/src/coding/ffmpeg_decoder.c | 4 ++-- Plugins/vgmstream/vgmstream/VGMInterface.m | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Frameworks/vgmstream/vgmstream/src/coding/ffmpeg_decoder.c b/Frameworks/vgmstream/vgmstream/src/coding/ffmpeg_decoder.c index fa971d2cc..b6ff1e24c 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/ffmpeg_decoder.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/ffmpeg_decoder.c @@ -218,7 +218,7 @@ static int ffmpeg_read(void* opaque, uint8_t* buf, int read_size) { if (data->logical_offset + read_size > data->logical_size) read_size = data->logical_size - data->logical_offset; if (read_size == 0) - return bytes; + return AVERROR_EOF; /* handle reads on inserted header */ if (data->header_size && data->logical_offset < data->header_size) { @@ -232,7 +232,7 @@ static int ffmpeg_read(void* opaque, uint8_t* buf, int read_size) { data->logical_offset += max_to_copy; if (read_size == 0) { - return max_to_copy; /* offset still in header */ + return max_to_copy ? max_to_copy : AVERROR_EOF; /* offset still in header */ } } diff --git a/Plugins/vgmstream/vgmstream/VGMInterface.m b/Plugins/vgmstream/vgmstream/VGMInterface.m index ff00ef622..9f9564993 100644 --- a/Plugins/vgmstream/vgmstream/VGMInterface.m +++ b/Plugins/vgmstream/vgmstream/VGMInterface.m @@ -303,14 +303,6 @@ static STREAMFILE* open_cog_streamfile_buffer_from_url(NSURL* url, const char* c if (![infile seekable]) return NULL; - // XXX Goddammit, FFmpeg - uint8_t sig[3]; - if ([infile read:sig amount:3] == 3) { - [infile seek:0 whence:SEEK_SET]; - if (memcmp(sig, "PSF", 3) == 0) - return NULL; - } - return open_cog_streamfile_buffer_by_file(infile, filename, bufsize); }