Skip to content

Commit

Permalink
Remove pointless file size function
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik committed Apr 2, 2024
1 parent 31ce21e commit 3558032
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/audiosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class BestAudioSource {
std::unique_ptr<LWAudioDecoder> Decoders[MaxVideoSources];
int64_t PreRoll = 40;
int64_t SampleDelay = 0;
int64_t FileSize = -1;
static constexpr size_t RetrySeekAttempts = 10;
std::set<int64_t> BadSeekLocations;
void SetLinearMode();
Expand Down
13 changes: 0 additions & 13 deletions src/bsshared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/bsshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/videosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class BestVideoSource {
uint64_t DecoderLastUse[MaxVideoSources] = {};
std::unique_ptr<LWVideoDecoder> Decoders[MaxVideoSources];
int64_t PreRoll = 20;
int64_t FileSize = -1;
static constexpr size_t RetrySeekAttempts = 10;
std::set<int64_t> BadSeekLocations;
void SetLinearMode();
Expand Down

0 comments on commit 3558032

Please sign in to comment.