Skip to content

Commit

Permalink
bestsource: Clean index cache when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Jan 31, 2023
1 parent e2fb3a7 commit 15f4da6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/audio_provider_bestsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ BSAudioProvider::BSAudioProvider(agi::fs::path const& filename, agi::BackgroundR
LOG_D("bs") << "File cached and has exact samples.";
}
});
BSCleanCache();
properties = bs.GetAudioProperties();
float_samples = properties.IsFloat;
bytes_per_sample = properties.BytesPerSample;
Expand Down
7 changes: 7 additions & 0 deletions src/bestsource_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "bestsource_common.h"

#include "options.h"
#include "utils.h"

#include <libaegisub/fs.h>
#include <libaegisub/path.h>
Expand All @@ -45,5 +46,11 @@ std::string GetBSCacheFile(agi::fs::path const& filename) {
return result.string();
}

void BSCleanCache() {
CleanCache(config::path->Decode("?local/bsindex/"),
"*.json",
OPT_GET("Provider/BestSource/Cache/Size")->GetInt(),
OPT_GET("Provider/BestSource/Cache/Files")->GetInt());
}

#endif // WITH_BESTSOURCE
3 changes: 2 additions & 1 deletion src/bestsource_common.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, arch1t3cht <[email protected]>>
// Copyright (c) 2022, arch1t3cht <[email protected]>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
Expand All @@ -24,5 +24,6 @@
#include <libaegisub/fs_fwd.h>

std::string GetBSCacheFile(agi::fs::path const& filename);
void BSCleanCache();

#endif /* WITH_BESTSOURCE */
6 changes: 6 additions & 0 deletions src/libresrc/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@
"Index All Tracks" : true,
"Log Level" : "quiet"
},
"BestSource" : {
"Cache" : {
"Files" : 100,
"Size" : 42
}
},
"Video" : {
"Cache" : {
"Size" : 32
Expand Down
6 changes: 6 additions & 0 deletions src/libresrc/osx/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@
"Index All Tracks" : true,
"Log Level" : "quiet"
},
"BestSource" : {
"Cache" : {
"Files" : 100,
"Size" : 42
}
},
"Video" : {
"Cache" : {
"Size" : 32
Expand Down
2 changes: 2 additions & 0 deletions src/video_provider_bestsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ BSVideoProvider::BSVideoProvider(agi::fs::path const& filename, std::string cons
}
});

BSCleanCache();

// Decode the first frame to get the color space
std::unique_ptr<BestVideoFrame> frame(bs.GetFrame(0));
colorspace = colormatrix_description(frame->GetAVFrame());
Expand Down

0 comments on commit 15f4da6

Please sign in to comment.