From 1ceb8bf623e8537a0fe16c6b369db2791b69eb29 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 11:16:27 +0900 Subject: [PATCH] =?UTF-8?q?=E6=98=A0=E5=83=8F=E3=82=BD=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92=E9=81=B8=E3=81=B6=E5=88=A4=E6=96=AD=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge/Sources/ProxySourceProvider.cs | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ProxyForge/Sources/ProxySourceProvider.cs diff --git a/ProxyForge/Sources/ProxySourceProvider.cs b/ProxyForge/Sources/ProxySourceProvider.cs new file mode 100644 index 0000000..eea1ca4 --- /dev/null +++ b/ProxyForge/Sources/ProxySourceProvider.cs @@ -0,0 +1,67 @@ +using ProxyForge.Cache; +using ProxyForge.Encoding; +using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Plugin.FileSource; + +namespace ProxyForge.Sources; + +internal sealed class ProxySourceProvider( + ProxyCache cache, + ProxyGenerationQueue queue, + Func isExporting, + Func settings, + VideoSourceFactory factory) +{ + public IVideoFileSource? Create(IGraphicsDevicesAndContext devices, string filePath) + { + var current = settings(); + if (!current.IsEnabled || isExporting()) + return null; + + var identity = SourceIdentity.Of(filePath); + if (identity is not { } source || source.Length < current.MinimumFileSizeBytes || cache.IsSkipped(source)) + return null; + + var scale = current.Scale; + var entry = cache.Find(source, scale); + if (entry is not null) + { + var proxy = TryOpen(devices, entry); + if (proxy is not null) + return ProxyVideoSource.FromProxy(devices, proxy.Value, new TimeSpan(entry.DurationTicks)); + } + + if (queue.HasFailed(source, scale)) + return null; + if (!current.GeneratesAutomatically && !queue.IsPending(source, scale)) + return null; + + var original = factory(devices, filePath); + if (original is null) + return null; + + if (current.GeneratesAutomatically) + queue.TryEnqueue(source, scale); + + var wrapper = ProxyVideoSource.FromOriginal(devices, original); + wrapper.AttachLoader(new ProxyUpgradeLoader(wrapper, devices, source, scale, cache, queue, factory)); + return wrapper; + } + + OpenedProxy? TryOpen(IGraphicsDevicesAndContext devices, ProxyCacheEntry entry) + { + try + { + var opened = OpenedProxy.Open(devices, cache.GetFilePath(entry), entry, factory); + if (opened is not null) + return opened; + } + catch (Exception exception) + { + Log.Default.Write($"ProxyForge: キャッシュしたプロキシを開けませんでした。{entry.SourcePath}", exception); + } + + cache.Remove(entry.Id); + return null; + } +}