diff --git a/src/audiosource.cpp b/src/audiosource.cpp index 5792929..e560322 100644 --- a/src/audiosource.cpp +++ b/src/audiosource.cpp @@ -384,7 +384,8 @@ BestAudioSource::BestAudioSource(const std::string &SourceFile, int Track, int A Decoder->GetAudioProperties(AP); AudioTrack = Decoder->GetTrack(); - + FileSize = Decoder->GetSourceSize(); + if (!ReadAudioTrackIndex(CachePath.empty() ? SourceFile : CachePath)) { if (!IndexTrack(Progress)) throw BestSourceException("Indexing of '" + SourceFile + "' track #" + std::to_string(AudioTrack) + " failed"); @@ -1115,7 +1116,7 @@ bool BestAudioSource::ReadAudioTrackIndex(const std::string &CachePath) { return false; if (!ReadBSHeader(F, false)) return false; - if (!ReadCompareInt64(F, GetFileSize(Source))) + if (!ReadCompareInt64(F, FileSize)) return false; if (!ReadCompareInt(F, AudioTrack)) return false; diff --git a/src/audiosource.h b/src/audiosource.h index 08bcbf4..2f2dff0 100644 --- a/src/audiosource.h +++ b/src/audiosource.h @@ -158,6 +158,7 @@ class BestAudioSource { std::unique_ptr Decoders[MaxVideoSources]; int64_t PreRoll = 40; int64_t SampleDelay = 0; + int64_t FileSize = -1; static constexpr size_t RetrySeekAttempts = 10; std::set BadSeekLocations; void SetLinearMode(); diff --git a/src/bsshared.cpp b/src/bsshared.cpp index 1052036..00747e5 100644 --- a/src/bsshared.cpp +++ b/src/bsshared.cpp @@ -82,19 +82,6 @@ file_ptr_t OpenFile(const std::string &Filename, bool Write) { return F; } -int64_t GetFileSize(const std::string &Filename) { - file_ptr_t F = OpenFile(Filename, false); -#ifdef _WIN32 - if (fseek(F.get(), 0, SEEK_END) != 0) - return -1; - return _ftelli64(F.get()); -#else - if (fseeko(F.get(), 0, SEEK_END) != 0) - return -1; - return ftello(F.get()); -#endif -} - file_ptr_t OpenCacheFile(const std::string &CachePath, int Track, bool Write) { return OpenFile(CachePath + "." + std::to_string(Track) + ".bsindex", Write); } diff --git a/src/bsshared.h b/src/bsshared.h index 4077dd8..85244b1 100644 --- a/src/bsshared.h +++ b/src/bsshared.h @@ -62,7 +62,6 @@ void SetBSDebugOutput(bool DebugOutput); void BSDebugPrint(const std::string_view Message, int64_t RequestedN = -1, int64_t CurrentN = -1); file_ptr_t OpenFile(const std::string &Filename, bool Write); -int64_t GetFileSize(const std::string &Filename); file_ptr_t OpenCacheFile(const std::string &CachePath, int Track, bool Write); void WriteByte(file_ptr_t &F, uint8_t Value); void WriteInt(file_ptr_t &F, int Value); diff --git a/src/version.h b/src/version.h index 5a5957d..a7e61b5 100644 --- a/src/version.h +++ b/src/version.h @@ -22,6 +22,6 @@ #define VERSION_H #define BEST_SOURCE_VERSION_MAJOR 2 -#define BEST_SOURCE_VERSION_MINOR 97 +#define BEST_SOURCE_VERSION_MINOR -21 #endif \ No newline at end of file diff --git a/src/videosource.cpp b/src/videosource.cpp index 4c6af5c..f0fe0d4 100644 --- a/src/videosource.cpp +++ b/src/videosource.cpp @@ -787,6 +787,7 @@ BestVideoSource::BestVideoSource(const std::string &SourceFile, const std::strin Decoder->GetVideoProperties(VP); VideoTrack = Decoder->GetTrack(); + FileSize = Decoder->GetSourceSize(); if (!ReadVideoTrackIndex(CachePath.empty() ? SourceFile : CachePath)) { if (!IndexTrack(Progress)) @@ -1306,7 +1307,7 @@ bool BestVideoSource::WriteVideoTrackIndex(const std::string &CachePath) { if (!F) return false; WriteBSHeader(F, true); - WriteInt64(F, GetFileSize(Source)); + WriteInt64(F, FileSize); WriteInt(F, VideoTrack); WriteInt(F, VariableFormat); WriteString(F, HWDevice); @@ -1383,7 +1384,7 @@ bool BestVideoSource::ReadVideoTrackIndex(const std::string &CachePath) { return false; if (!ReadBSHeader(F, true)) return false; - if (!ReadCompareInt64(F, GetFileSize(Source))) + if (!ReadCompareInt64(F, FileSize)) return false; if (!ReadCompareInt(F, VideoTrack)) return false; diff --git a/src/videosource.h b/src/videosource.h index 57f4ca4..a1883b1 100644 --- a/src/videosource.h +++ b/src/videosource.h @@ -240,6 +240,7 @@ class BestVideoSource { uint64_t DecoderLastUse[MaxVideoSources] = {}; std::unique_ptr Decoders[MaxVideoSources]; int64_t PreRoll = 20; + int64_t FileSize = -1; static constexpr size_t RetrySeekAttempts = 10; std::set BadSeekLocations; void SetLinearMode();