From 15f4da61d3e5b47a3d3d8775f5f78be07de4e25a Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Tue, 31 Jan 2023 02:47:02 +0100 Subject: [PATCH] bestsource: Clean index cache when necessary --- src/audio_provider_bestsource.cpp | 1 + src/bestsource_common.cpp | 7 +++++++ src/bestsource_common.h | 3 ++- src/libresrc/default_config.json | 6 ++++++ src/libresrc/osx/default_config.json | 6 ++++++ src/video_provider_bestsource.cpp | 2 ++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/audio_provider_bestsource.cpp b/src/audio_provider_bestsource.cpp index 5390788dc..aa1bd1904 100644 --- a/src/audio_provider_bestsource.cpp +++ b/src/audio_provider_bestsource.cpp @@ -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; diff --git a/src/bestsource_common.cpp b/src/bestsource_common.cpp index 69d627015..2cd478ef6 100644 --- a/src/bestsource_common.cpp +++ b/src/bestsource_common.cpp @@ -23,6 +23,7 @@ #include "bestsource_common.h" #include "options.h" +#include "utils.h" #include #include @@ -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 diff --git a/src/bestsource_common.h b/src/bestsource_common.h index b93ccc815..53ab39fe4 100644 --- a/src/bestsource_common.h +++ b/src/bestsource_common.h @@ -1,4 +1,4 @@ -// Copyright (c) 2022, arch1t3cht > +// Copyright (c) 2022, arch1t3cht // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -24,5 +24,6 @@ #include std::string GetBSCacheFile(agi::fs::path const& filename); +void BSCleanCache(); #endif /* WITH_BESTSOURCE */ diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index a530abb17..ced08ca0b 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -350,6 +350,12 @@ "Index All Tracks" : true, "Log Level" : "quiet" }, + "BestSource" : { + "Cache" : { + "Files" : 100, + "Size" : 42 + } + }, "Video" : { "Cache" : { "Size" : 32 diff --git a/src/libresrc/osx/default_config.json b/src/libresrc/osx/default_config.json index a857a6bf0..cf2f27b12 100644 --- a/src/libresrc/osx/default_config.json +++ b/src/libresrc/osx/default_config.json @@ -350,6 +350,12 @@ "Index All Tracks" : true, "Log Level" : "quiet" }, + "BestSource" : { + "Cache" : { + "Files" : 100, + "Size" : 42 + } + }, "Video" : { "Cache" : { "Size" : 32 diff --git a/src/video_provider_bestsource.cpp b/src/video_provider_bestsource.cpp index a75a8c676..14804f4a0 100644 --- a/src/video_provider_bestsource.cpp +++ b/src/video_provider_bestsource.cpp @@ -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 frame(bs.GetFrame(0)); colorspace = colormatrix_description(frame->GetAVFrame());