fix(proxies): use only a frame's own proxy and let tiers, reports and built flags follow it
- Renders, analyses, the server's manifests and proxy downloads take a proxy only when its Exif capture time is the frame's (ArchiveImages.IsProxyOf); one left at the index by a frame renumbered since counts as missing and is asked for again (V-24). - A frame whose original the host reads through its proxy (HEIF on the server) is preview-only only while it has none: the light analysis and the proxy pass keep the flag, the preview-only count, the light finding and the advisor's output cap in step with the proxies, and an arriving proxy queues a light analysis on the server (V-1, V-25). - The deep checkpoint's content key includes whether each frame is read from its original or its proxy, and analysis.json lists the frames measured from proxies; an unreadable verdict on a frame now read from its proxy makes the report stale (V-26). - Thumbnails drawn from proxies are compared with the archive's thumbnail size instead of 320 px (V-27). - A resumed thumbnail or proxy pass sets ThumbsBuilt/ProxiesBuilt only when the frames an earlier run did still have theirs, and the proxy pass logs frames waiting for a client's proxy apart from unreadable ones (V-28). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
22 files changed
+601
-59
No files matched your search
@@ -10,7 +10,9 @@ using Titano.Core.Model;
|
||||
namespace Titano.Data.Archiving;
|
||||
|
||||
/// <summary>Frames processed by one thumbnail or proxy pass over a sequence.</summary>
|
||||
public sealed record ImagePassResult(int Built, int Reused, int Undecodable);
|
||||
/// <param name="Waiting">Frames of a proxy pass whose originals this host cannot decode and whose proxy it waits for from a
|
||||
/// client or render node that can (BRIEF §2.3): unlike <paramref name="Undecodable"/> ones, nothing is wrong with them.</param>
|
||||
public sealed record ImagePassResult(int Built, int Reused, int Undecodable, int Waiting = 0);
|
||||
|
||||
/// <summary>What became of a proxy sent by a client or render node (<see cref="ArchiveImages.StoreProxy"/>).</summary>
|
||||
public enum ProxyStoreResult
|
||||
@@ -86,6 +88,15 @@ public sealed class ArchiveImages
|
||||
/// </summary>
|
||||
public static bool ServerNeedsProxy(ImageFileFormat format) => NeedsProxy(ServerDecoders, format);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the file at <paramref name="proxy"/> (a sequence's <c>proxies/0001.jpg</c>) is the proxy of the frame
|
||||
/// captured at <paramref name="capturedAt"/>: its Exif capture time is the frame's, or the frame has none to compare
|
||||
/// with. Proxies are named by frame index, so one left by a frame renumbered since (frames inserted before it) is
|
||||
/// another photo's: renders, analyses and the server's manifests and downloads treat it as missing, and the proxy
|
||||
/// pass removes it (<see cref="BuildProxiesAsync"/>).
|
||||
/// </summary>
|
||||
public static bool IsProxyOf(string proxy, DateTime? capturedAt) => ReadProxy(proxy, capturedAt).Check is ProxyCheck.Current or ProxyCheck.Unverifiable;
|
||||
|
||||
/// <summary>
|
||||
/// A proxy of the original at <paramref name="path"/> for a server that cannot decode it (<see cref="StoreProxy"/>):
|
||||
/// at <paramref name="longEdge"/> (0 = full size) and <paramref name="quality"/>, with <paramref name="frame"/>'s capture
|
||||
@@ -148,7 +159,8 @@ public sealed class ArchiveImages
|
||||
return ProxyStoreResult.Stored;
|
||||
}
|
||||
|
||||
/// <param name="startFrame">Resume point inside the sequence (frames before it were done by an earlier run).</param>
|
||||
/// <param name="startFrame">Resume point inside the sequence (frames before it were done by an earlier run: the
|
||||
/// sequence's built status counts them as they are now).</param>
|
||||
/// <param name="checkpoint">Called with the next frame index whenever the pack has been committed.</param>
|
||||
public async Task<ImagePassResult> BuildThumbnailsAsync(Archive archive, Sequence sequence, bool force, int startFrame,
|
||||
Func<int, int, ValueTask> checkpoint, CancellationToken cancellationToken = default)
|
||||
@@ -159,6 +171,7 @@ public sealed class ArchiveImages
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
int built = 0, reused = 0, undecodable = 0;
|
||||
var complete = true;
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
var companions = await GprCompanions.FindAsync(_db, archive, manifest.Frames, cancellationToken).ConfigureAwait(false);
|
||||
// Thumbnail writers exclude each other only; ingest keeps committing meanwhile.
|
||||
@@ -166,6 +179,12 @@ public sealed class ArchiveImages
|
||||
_writer.Options.LeaseDuration, cancellationToken).ConfigureAwait(false))
|
||||
using (var pack = ThumbPackWriter.Open(folder.ThumbsPackPath))
|
||||
{
|
||||
for (var i = 0; i < startFrame && i < manifest.Frames.Count; i++)
|
||||
{
|
||||
var frame = manifest.Frames[i];
|
||||
complete &= pack.Entries.GetValueOrDefault(frame.I) is { } entry
|
||||
&& entry.SourceHash.AsSpan().SequenceEqual(ThumbPack.Fingerprint(frame.Sha256, frame.File, frame.Size));
|
||||
}
|
||||
var cadence = new Cadence();
|
||||
for (var i = startFrame; i < manifest.Frames.Count; i++)
|
||||
{
|
||||
@@ -178,9 +197,9 @@ public sealed class ArchiveImages
|
||||
// A frame this host cannot decode shows its proxy once one arrived; until then its original's embedded
|
||||
// preview, whose smaller thumbnail the proxy's replaces.
|
||||
var fromProxy = false;
|
||||
if (NeedsProxy(frame.Format) && !(current && edge >= FrameImageRenderer.ThumbnailLongEdge)
|
||||
&& ReadProxy(folder.Proxy(frame.I), frame) is { Check: ProxyCheck.Current or ProxyCheck.Unverifiable } proxy)
|
||||
fromProxy = !current || edge < System.Math.Min(FrameImageRenderer.ThumbnailLongEdge, proxy.LongEdge);
|
||||
if (NeedsProxy(frame.Format) && !(current && edge >= policy.LongEdge)
|
||||
&& ReadProxy(folder.Proxy(frame.I), frame.CapturedAt) is { Check: ProxyCheck.Current or ProxyCheck.Unverifiable } proxy)
|
||||
fromProxy = !current || edge < System.Math.Min(policy.LongEdge, proxy.LongEdge);
|
||||
if (current && !fromProxy)
|
||||
{
|
||||
reused++;
|
||||
@@ -209,11 +228,17 @@ public sealed class ArchiveImages
|
||||
pack.Commit();
|
||||
}
|
||||
await _tiers.RecordAsync(archive, sequence, tiers, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ThumbsBuilt, undecodable == 0, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ThumbsBuilt, complete && undecodable == 0, cancellationToken).ConfigureAwait(false);
|
||||
return new ImagePassResult(built, reused, undecodable);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="BuildThumbnailsAsync"/>
|
||||
/// <remarks>
|
||||
/// <see cref="SequenceStatus.ProxiesBuilt"/> is set only when every frame has its proxy: a server asks clients and
|
||||
/// render nodes for none while it is set (BRIEF §2.3), so a pass resumed at <paramref name="startFrame"/> checks the
|
||||
/// proxies of the frames an earlier run did again (their headers only). The <see cref="FrameFlags.PreviewOnly"/> flag
|
||||
/// of frames this host reads through their proxies follows whether they have one (<see cref="FrameTiers"/>).
|
||||
/// </remarks>
|
||||
public async Task<ImagePassResult> BuildProxiesAsync(Archive archive, Sequence sequence, bool force, int startFrame,
|
||||
Func<int, int, ValueTask> checkpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -224,33 +249,41 @@ public sealed class ArchiveImages
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
Directory.CreateDirectory(folder.Proxies);
|
||||
int built = 0, reused = 0, undecodable = 0;
|
||||
int built = 0, reused = 0, undecodable = 0, waiting = 0;
|
||||
var complete = true;
|
||||
var tiers = new Dictionary<Guid, FileTier>();
|
||||
var proxied = new Dictionary<Guid, bool>();
|
||||
var companions = await GprCompanions.FindAsync(_db, archive, manifest.Frames, cancellationToken).ConfigureAwait(false);
|
||||
var cadence = new Cadence();
|
||||
for (var i = startFrame; i < manifest.Frames.Count; i++)
|
||||
for (var i = 0; i < manifest.Frames.Count; i++)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var frame = manifest.Frames[i];
|
||||
var path = folder.Proxy(frame.I);
|
||||
var done = i < startFrame;
|
||||
if (NeedsProxy(frame.Format))
|
||||
{
|
||||
// Only a client or render node that decodes the original makes this proxy: a preview would make one the
|
||||
// size of a thumbnail here. One left from a frame renumbered since goes, so it is asked for again, and so
|
||||
// does one smaller than the policy's (made here from a preview by an earlier version).
|
||||
var (check, longEdge) = ReadProxy(path, frame);
|
||||
var (check, longEdge) = ReadProxy(path, frame.CapturedAt);
|
||||
if (check is ProxyCheck.Current or ProxyCheck.Unverifiable && TooSmall(longEdge, frame.W, frame.H, policy)) check = ProxyCheck.Stale;
|
||||
if (check is ProxyCheck.Current or ProxyCheck.Unverifiable)
|
||||
{
|
||||
reused++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (check == ProxyCheck.Stale) File.Delete(path);
|
||||
undecodable++;
|
||||
}
|
||||
var usable = check is ProxyCheck.Current or ProxyCheck.Unverifiable;
|
||||
if (check == ProxyCheck.Stale) File.Delete(path);
|
||||
proxied[frame.Id] = usable;
|
||||
complete &= usable;
|
||||
if (done) continue;
|
||||
if (usable) reused++;
|
||||
else if ((frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0) undecodable++;
|
||||
else waiting++;
|
||||
}
|
||||
else if (!force && ReadProxy(path, frame).Check == ProxyCheck.Current)
|
||||
else if (done)
|
||||
{
|
||||
// Made by the earlier run, unless the frame did not decode then.
|
||||
complete &= ReadProxy(path, frame.CapturedAt).Check is ProxyCheck.Current or ProxyCheck.Unverifiable;
|
||||
continue;
|
||||
}
|
||||
else if (!force && ReadProxy(path, frame.CapturedAt).Check == ProxyCheck.Current)
|
||||
{
|
||||
reused++;
|
||||
continue;
|
||||
@@ -264,12 +297,13 @@ public sealed class ArchiveImages
|
||||
else
|
||||
{
|
||||
undecodable++;
|
||||
complete = false;
|
||||
}
|
||||
if (cadence.Due()) await checkpoint(i + 1, manifest.Frames.Count).ConfigureAwait(false);
|
||||
}
|
||||
await _tiers.RecordAsync(archive, sequence, tiers, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ProxiesBuilt, undecodable == 0, cancellationToken).ConfigureAwait(false);
|
||||
return new ImagePassResult(built, reused, undecodable);
|
||||
await _tiers.RecordAsync(archive, sequence, tiers, proxied, cancellationToken).ConfigureAwait(false);
|
||||
await MarkAsync(archive, paths, sequence, SequenceStatus.ProxiesBuilt, complete, cancellationToken).ConfigureAwait(false);
|
||||
return new ImagePassResult(built, reused, undecodable, waiting);
|
||||
}
|
||||
|
||||
/// <summary>Where a frame's proxy stands; only a capture time tells whether it is the frame's.</summary>
|
||||
@@ -287,15 +321,15 @@ public sealed class ArchiveImages
|
||||
Stale,
|
||||
}
|
||||
|
||||
/// <summary>Where the proxy at <paramref name="proxy"/> stands for <paramref name="frame"/>, and its long edge.</summary>
|
||||
private static (ProxyCheck Check, int LongEdge) ReadProxy(string proxy, SidecarFrame frame)
|
||||
/// <summary>Where the proxy at <paramref name="proxy"/> stands for the frame captured at <paramref name="capturedAt"/>, and its long edge.</summary>
|
||||
private static (ProxyCheck Check, int LongEdge) ReadProxy(string proxy, DateTime? capturedAt)
|
||||
{
|
||||
if (!File.Exists(proxy)) return (ProxyCheck.Missing, 0);
|
||||
try
|
||||
{
|
||||
var metadata = MetadataReader.Read(proxy);
|
||||
var (width, height) = metadata.OrientedSize;
|
||||
var check = frame.CapturedAt is null ? ProxyCheck.Unverifiable : metadata.CapturedAt == frame.CapturedAt ? ProxyCheck.Current : ProxyCheck.Stale;
|
||||
var check = capturedAt is null ? ProxyCheck.Unverifiable : metadata.CapturedAt == capturedAt ? ProxyCheck.Current : ProxyCheck.Stale;
|
||||
return (check, System.Math.Max(width, height));
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace Titano.Data.Archiving;
|
||||
/// shows a warning at once; its next light analysis lists them. Tiers describe the host that probed or decoded the files
|
||||
/// last. Only a file in a format this host decodes natively is flagged undecodable (it is damaged); one beyond this
|
||||
/// host's decoders (HEIF or an unsupported RAW without a preview on the server) keeps its tier but no flag, so render
|
||||
/// nodes and proxies can still provide its pixels, and a host that decodes a flagged frame clears the flag.
|
||||
/// nodes and proxies can still provide its pixels, and a host that decodes a flagged frame clears the flag. A frame whose
|
||||
/// original this host reads through its proxy (<see cref="ArchiveImages.NeedsProxy(ImageFileFormat)"/>) is preview-only
|
||||
/// only while it has none: with its proxy it is not rendered from the embedded preview, so it caps nothing.
|
||||
/// </summary>
|
||||
internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, ArchiveIndexer indexer)
|
||||
{
|
||||
@@ -49,15 +51,22 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
|
||||
return tiers;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="RecordAsync(Archive, Sequence, IReadOnlyDictionary{Guid, FileTier}, IReadOnlyDictionary{Guid, bool}?, CancellationToken)"/>
|
||||
public Task<IReadOnlyList<SidecarFrame>> RecordAsync(Archive archive, Sequence sequence, IReadOnlyDictionary<Guid, FileTier> tiers,
|
||||
CancellationToken cancellationToken) => RecordAsync(archive, sequence, tiers, null, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Records <paramref name="tiers"/> (by frame id) where they change what the sidecar says, and returns the frames that
|
||||
/// changed as they are now. Frames no longer in the sequence are ignored.
|
||||
/// </summary>
|
||||
/// <param name="proxied">By frame id, for frames whose original this host reads through its proxy, whether the frame's
|
||||
/// own proxy is there now (<see cref="SequenceFrames.WithProxy"/>); their <see cref="FrameFlags.PreviewOnly"/> follows
|
||||
/// it even where no tier is recorded.</param>
|
||||
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
|
||||
public async Task<IReadOnlyList<SidecarFrame>> RecordAsync(Archive archive, Sequence sequence, IReadOnlyDictionary<Guid, FileTier> tiers,
|
||||
CancellationToken cancellationToken)
|
||||
IReadOnlyDictionary<Guid, bool>? proxied, CancellationToken cancellationToken)
|
||||
{
|
||||
if (tiers.Count == 0) return [];
|
||||
if (tiers.Count == 0 && proxied is not { Count: > 0 }) return [];
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
ArchiveVolume.EnsureWritable(paths);
|
||||
var changed = new List<SidecarFrame>();
|
||||
@@ -70,8 +79,11 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
|
||||
{
|
||||
var frame = m.Frames[i];
|
||||
frames[i] = frame;
|
||||
if (!tiers.TryGetValue(frame.Id, out var tier)) continue;
|
||||
var updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format));
|
||||
bool? hasProxy = proxied is not null && proxied.TryGetValue(frame.Id, out var found) ? found : null;
|
||||
SidecarFrame updated;
|
||||
if (tiers.TryGetValue(frame.Id, out var tier)) updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format), hasProxy == true);
|
||||
else if (hasProxy is { } proxy) updated = SequenceFrames.WithProxy(frame, proxy);
|
||||
else continue;
|
||||
if (updated.Tier == frame.Tier && updated.Flags == frame.Flags && updated.PreviewW == frame.PreviewW && updated.PreviewH == frame.PreviewH)
|
||||
continue;
|
||||
gained |= (updated.Flags & ~frame.Flags & FrameFlags.Undecodable) != 0;
|
||||
|
||||
@@ -34,7 +34,9 @@ internal sealed class ImageJobHandler(TitanoDatabase db, ArchiveImages images, J
|
||||
var result = kind == JobKind.Thumbs
|
||||
? await images.BuildThumbnailsAsync(archive, sequence, force, start, Checkpoint, context.Cancellation).ConfigureAwait(false)
|
||||
: await images.BuildProxiesAsync(archive, sequence, force, start, Checkpoint, context.Cancellation).ConfigureAwait(false);
|
||||
context.Log(Loc.L("Archive.Log.ImagesDone", sequence.DisplayTitle, result.Built, result.Reused, result.Undecodable));
|
||||
context.Log(kind == JobKind.Thumbs
|
||||
? Loc.L("Archive.Log.ImagesDone", sequence.DisplayTitle, result.Built, result.Reused, result.Undecodable)
|
||||
: Loc.L("Archive.Log.ProxiesDone", sequence.DisplayTitle, result.Built, result.Reused, result.Undecodable, result.Waiting));
|
||||
await context.CheckpointAsync(string.Create(CultureInfo.InvariantCulture, $"{s + 1}:0"), s + 1, targets.Count).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions opti
|
||||
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, parameters.UseProxies, options.Archive.Decoder, cancellation).ConfigureAwait(false);
|
||||
var companions = await GprCompanions.FindAsync(db, archive, frames.Frames, cancellation).ConfigureAwait(false);
|
||||
IReadOnlyList<TargetOutcome> outcomes;
|
||||
await using (var render = new SequenceRender(frames, project, SequenceAnalyser.ReadReport(folder, frames.Count), options, originals: !parameters.UseProxies,
|
||||
await using (var render = new SequenceRender(frames, project, SequenceAnalyser.ReadReport(folder, frames), options, originals: !parameters.UseProxies,
|
||||
companions))
|
||||
{
|
||||
outcomes = await render.RenderAllAsync(
|
||||
|
||||
@@ -45,21 +45,23 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
ArchiveVolume.EnsureWritable(paths);
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, options.Archive.Decoder, cancellationToken).ConfigureAwait(false);
|
||||
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders.
|
||||
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders. A frame
|
||||
// read from its proxy is not preview-only whatever its original's tier, so it caps nothing (BRIEF §8.1, §8.2).
|
||||
var probed = await _tiers.ProbeUnknownAsync(archive, folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, cancellationToken).ConfigureAwait(false));
|
||||
var proxied = frames.ProxyStates(options.Archive.Decoder);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, proxied, cancellationToken).ConfigureAwait(false));
|
||||
var metadata = frames.LightFrames();
|
||||
|
||||
DeepAnalysisReport? report;
|
||||
if (deep)
|
||||
{
|
||||
(report, var decoded) = await AnalyseDeepAsync(archive, frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, cancellationToken).ConfigureAwait(false));
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, proxied, cancellationToken).ConfigureAwait(false));
|
||||
metadata = [.. metadata.Select((m, i) => m with { Flags = frames.Frames[i].Flags })];
|
||||
}
|
||||
else
|
||||
{
|
||||
report = ReadReport(folder, frames.Count);
|
||||
report = ReadReport(folder, frames);
|
||||
}
|
||||
var light = LightAnalyzer.Analyze(metadata);
|
||||
var context = SequenceContext.FromFrames(frames.Frames, options.AdvisorCodecs);
|
||||
@@ -85,7 +87,7 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
// then either sees that report or runs before it is recorded, and never clears what it recorded.
|
||||
await using (await writer.LockAsync(paths, sequence.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
report ??= ReadReport(folder, frames.Count);
|
||||
report ??= ReadReport(folder, frames);
|
||||
warnings = Advisor.Recommend(light, report, context).Findings.Count(f => f.Severity >= FindingSeverity.Warning);
|
||||
var set = SequenceStatus.AnalyzedLight | (report is null ? SequenceStatus.None : SequenceStatus.AnalyzedDeep)
|
||||
| (warnings > 0 ? SequenceStatus.HasWarnings : SequenceStatus.None);
|
||||
@@ -103,7 +105,25 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
return new AnalysisOutcome(sequence, frames.Count, warnings, changed, unreadable, presets);
|
||||
}
|
||||
|
||||
/// <summary>The saved deep report when it describes the current frames; null when absent, stale or unreadable.</summary>
|
||||
/// <summary>
|
||||
/// The saved deep report when it describes <paramref name="frames"/> as this host reads them now: also stale when a
|
||||
/// frame it found unreadable has been read from its proxy since (one sent for an original this host cannot decode,
|
||||
/// BRIEF §2.3), so that verdict and the frame's missing measurements no longer hold.
|
||||
/// </summary>
|
||||
public static DeepAnalysisReport? ReadReport(SequencePaths folder, SequenceFrames frames)
|
||||
{
|
||||
var report = ReadReport(folder, frames.Count);
|
||||
if (report is null || frames.Proxied is not { } proxied) return report;
|
||||
HashSet<int> measured = report.ProxyFrames is { } read ? [.. read] : [];
|
||||
foreach (var index in report.Issues.Undecodable)
|
||||
{
|
||||
if (index < frames.Count && proxied[index] && !measured.Contains(index) && (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) == 0)
|
||||
return null;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
/// <summary>The saved deep report when it covers <paramref name="frameCount"/> frames; null when absent, stale or unreadable.</summary>
|
||||
public static DeepAnalysisReport? ReadReport(SequencePaths folder, int frameCount)
|
||||
{
|
||||
if (!File.Exists(folder.AnalysisPath)) return null;
|
||||
@@ -179,6 +199,9 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
.ConfigureAwait(false);
|
||||
decoded = Decoded(frames, report, source, companions, cancellationToken);
|
||||
}
|
||||
// An unreadable verdict on a frame read from its original goes stale once the frame has a proxy (ReadReport).
|
||||
int[] fromProxies = [.. Enumerable.Range(0, frames.Count).Where(i => frames.Proxied?[i] == true)];
|
||||
report = report with { ProxyFrames = fromProxies.Length > 0 ? fromProxies : null };
|
||||
report.Save(folder.AnalysisPath);
|
||||
file.Delete();
|
||||
|
||||
@@ -191,11 +214,17 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
}
|
||||
|
||||
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the
|
||||
/// same count) make it stale, like changed options do.</summary>
|
||||
/// same count), or now read from their proxies where they were read from their originals (or the other way round),
|
||||
/// make it stale, like changed options do.</summary>
|
||||
private static string ContentKey(SequenceFrames frames)
|
||||
{
|
||||
using var hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
|
||||
foreach (var f in frames.Frames) hash.AppendData(Encoding.UTF8.GetBytes($"{f.Id:N}/{f.Sha256}/{f.Size}/{f.Flags & SequenceFrames.NotAnalysed};"));
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
var f = frames.Frames[i];
|
||||
var source = frames.Proxied is { } proxied && proxied[i] ? "proxy" : "original";
|
||||
hash.AppendData(Encoding.UTF8.GetBytes($"{f.Id:N}/{f.Sha256}/{f.Size}/{f.Flags & SequenceFrames.NotAnalysed}/{source};"));
|
||||
}
|
||||
return Convert.ToHexStringLower(hash.GetHashAndReset())[..16];
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
/// <summary>
|
||||
/// Every frame row of <paramref name="sequence"/> with its archive file: the proxy when asked, and whenever the
|
||||
/// original is one <paramref name="decoder"/> cannot decode (<see cref="ArchiveImages.NeedsProxy(ImageDecoder, ImageFileFormat)"/>:
|
||||
/// HEIF on the server, BRIEF §2.3, §8.5), as long as the proxy exists; else the original.
|
||||
/// HEIF on the server, BRIEF §2.3, §8.5), as long as the frame's own proxy is there (<see cref="ArchiveImages.IsProxyOf"/>:
|
||||
/// not one left at its index by a frame renumbered since); else the original.
|
||||
/// </summary>
|
||||
public static async Task<SequenceFrames> LoadAsync(TitanoDatabase db, Archive archive, Sequence sequence, bool useProxies, ImageDecoder decoder,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -51,7 +52,7 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
if ((frame.Flags & FrameFlags.Missing) != 0) continue;
|
||||
originals[i] = paths.FromRelative(frame.RelativePath);
|
||||
var proxy = useProxies || ArchiveImages.NeedsProxy(decoder, frame.Format) ? folder.Proxy(frame.Index) : null;
|
||||
proxied[i] = proxy is not null && File.Exists(proxy);
|
||||
proxied[i] = proxy is not null && ArchiveImages.IsProxyOf(proxy, frame.CapturedAt);
|
||||
files[i] = proxied[i] ? proxy : originals[i];
|
||||
}
|
||||
return new SequenceFrames(sequence, frames, files) { Proxied = proxied, Originals = originals };
|
||||
@@ -94,6 +95,22 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
|
||||
return light;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// By frame id, whether each frame whose original <paramref name="decoder"/> cannot decode (it is read from its proxy,
|
||||
/// <see cref="LoadAsync"/>) has its own proxy now: what its <see cref="FrameFlags.PreviewOnly"/> follows
|
||||
/// (<see cref="FrameTiers.RecordAsync(Archive, Sequence, IReadOnlyDictionary{Guid, FileTier}, IReadOnlyDictionary{Guid, bool}?, CancellationToken)"/>).
|
||||
/// Missing frames are left out.
|
||||
/// </summary>
|
||||
public Dictionary<Guid, bool> ProxyStates(ImageDecoder decoder)
|
||||
{
|
||||
var states = new Dictionary<Guid, bool>();
|
||||
for (var i = 0; i < Frames.Count; i++)
|
||||
{
|
||||
if (Files[i] is not null && ArchiveImages.NeedsProxy(decoder, Frames[i].Format)) states[Frames[i].Id] = Proxied is { } proxied && proxied[i];
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
/// <summary>Positions of the frames a render must skip besides the project's exclusions.</summary>
|
||||
public IEnumerable<int> NotRenderable()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user