vapoursynth: Add a preferred cache directory and clean it when necessary

This commit is contained in:
arch1t3cht 2023-01-31 21:35:24 +01:00
parent 32aaf6372c
commit c348f8582a
6 changed files with 26 additions and 0 deletions

View file

@ -56,6 +56,8 @@ public:
VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename) try { VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename) try {
std::lock_guard<std::mutex> lock(vs.GetMutex()); std::lock_guard<std::mutex> lock(vs.GetMutex());
VSCleanCache();
script = vs.GetScriptAPI()->createScript(nullptr); script = vs.GetScriptAPI()->createScript(nullptr);
if (script == nullptr) { if (script == nullptr) {
throw VapoursynthError("Error creating script API"); throw VapoursynthError("Error creating script API");

View file

@ -353,6 +353,12 @@
"Index All Tracks" : true, "Index All Tracks" : true,
"Log Level" : "quiet" "Log Level" : "quiet"
}, },
"VapourSynth" : {
"Cache" : {
"Files" : 500,
"Size" : 1000
}
},
"Video" : { "Video" : {
"Cache" : { "Cache" : {
"Size" : 32 "Size" : 32

View file

@ -353,6 +353,12 @@
"Index All Tracks" : true, "Index All Tracks" : true,
"Log Level" : "quiet" "Log Level" : "quiet"
}, },
"VapourSynth" : {
"Cache" : {
"Files" : 500,
"Size" : 1000
}
},
"Video" : { "Video" : {
"Cache" : { "Cache" : {
"Size" : 32 "Size" : 32

View file

@ -19,6 +19,7 @@
#include "vapoursynth_wrap.h" #include "vapoursynth_wrap.h"
#include "options.h" #include "options.h"
#include "utils.h"
#include <libaegisub/fs.h> #include <libaegisub/fs.h>
#include <libaegisub/path.h> #include <libaegisub/path.h>
@ -39,6 +40,7 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip
throw VapoursynthError("Failed to create VSMap for script info"); throw VapoursynthError("Failed to create VSMap for script info");
SetStringVar(api, map, "filename", filename.string()); SetStringVar(api, map, "filename", filename.string());
SetStringVar(api, map, "__aegi_vscache", config::path->Decode("?local/vscache").string());
for (std::string dir : { "data", "dictionary", "local", "script", "temp", "user", }) for (std::string dir : { "data", "dictionary", "local", "script", "temp", "user", })
// Don't include ?audio and ?video in here since these only hold the paths to the previous audio/video files. // Don't include ?audio and ?video in here since these only hold the paths to the previous audio/video files.
SetStringVar(api, map, "__aegi_" + dir, config::path->Decode("?" + dir).string()); SetStringVar(api, map, "__aegi_" + dir, config::path->Decode("?" + dir).string());
@ -58,4 +60,11 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip
return result; return result;
} }
void VSCleanCache() {
CleanCache(config::path->Decode("?local/vscache/"),
"",
OPT_GET("Provider/VapourSynth/Cache/Size")->GetInt(),
OPT_GET("Provider/VapourSynth/Cache/Files")->GetInt());
}
#endif // WITH_VAPOURSYNTH #endif // WITH_VAPOURSYNTH

View file

@ -20,5 +20,6 @@
#include <libaegisub/fs_fwd.h> #include <libaegisub/fs_fwd.h>
int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *script, agi::fs::path const& filename, std::string default_script); int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *script, agi::fs::path const& filename, std::string default_script);
void VSCleanCache();
#endif // WITH_VAPOURSYNTH #endif // WITH_VAPOURSYNTH

View file

@ -111,6 +111,8 @@ void VapoursynthVideoProvider::SetResizeArg(VSMap *args, const VSMap *props, con
VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix) try { VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix) try {
std::lock_guard<std::mutex> lock(vs.GetMutex()); std::lock_guard<std::mutex> lock(vs.GetMutex());
VSCleanCache();
script = vs.GetScriptAPI()->createScript(nullptr); script = vs.GetScriptAPI()->createScript(nullptr);
if (script == nullptr) { if (script == nullptr) {
throw VapoursynthError("Error creating script API"); throw VapoursynthError("Error creating script API");