merge: proxy and decode-tier fixes (V-1, V-24, V-25, V-26, V-27, V-28)

Merge branch fix2/proxies-tiers into the verification branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 16:54:07 +00:00
commit e9870f4e88
28 files changed
+1049 -92

No files matched your search

@@ -161,6 +161,13 @@ public sealed record DeepAnalysisReport
/// <summary>Suggested hero frame: sharp, well exposed, near golden hour or mid-sequence, not excluded.</summary>
public int? HeroIndex { get; init; }
/// <summary>
/// Frames measured from their proxies, ascending, because the analysing host cannot decode their originals (HEIF on the
/// server, BRIEF §2.3); null when none were. An unreadable verdict on a frame read from its original no longer holds
/// once the frame is read from a proxy.
/// </summary>
public int[]? ProxyFrames { get; init; }
public IReadOnlyList<DeepFinding> Findings { get; init; } = [];
public string ToJson() => JsonSerializer.Serialize(this, DeepAnalysisJson.Default.DeepAnalysisReport);
+14 -2
View File
@@ -57,10 +57,12 @@ public static class SequenceFrames
/// <param name="damaged">For the unavailable tier: whether that proves the file unreadable. False when the host has no
/// native decoder for the format, so a client or render node with one (or a proxy) may still produce its pixels: the
/// tier is kept and <see cref="FrameFlags.Undecodable"/> is left as it was.</param>
public static SidecarFrame WithTier(SidecarFrame frame, FileTier tier, bool damaged = true)
/// <param name="proxied">Whether the host takes the frame's pixels from its proxy (an original it cannot decode, whose
/// proxy is there): see <see cref="WithProxy"/>.</param>
public static SidecarFrame WithTier(SidecarFrame frame, FileTier tier, bool damaged = true, bool proxied = false)
{
var flags = frame.Flags & ~(FrameFlags.PreviewOnly | FrameFlags.Undecodable);
if (tier.Tier == DecodeTier.EmbeddedPreview) flags |= FrameFlags.PreviewOnly;
if (tier.Tier == DecodeTier.EmbeddedPreview) flags |= proxied ? FrameFlags.None : FrameFlags.PreviewOnly;
else if (tier.Tier == DecodeTier.Unavailable) flags |= damaged ? FrameFlags.Undecodable : frame.Flags & FrameFlags.Undecodable;
var (w, h) = tier.Tier == DecodeTier.EmbeddedPreview && tier.Width > 0 && tier.Height > 0
? PixelConvert.OrientedSize(tier.Width, tier.Height, frame.Orientation)
@@ -68,6 +70,16 @@ public static class SequenceFrames
return frame with { Tier = tier.Tier, Flags = flags, PreviewW = Positive(w), PreviewH = Positive(h) };
}
/// <summary>
/// The frame with <see cref="FrameFlags.PreviewOnly"/> following its proxy, for a host that takes the pixels of the
/// frame's original from its proxy (HEIF on the server, BRIEF §2.3, §8.1): an embedded-preview frame is read from its
/// preview, so preview-only, only while <paramref name="proxied"/> is false. The tier and the preview size stay the
/// original's; other tiers are left as they are.
/// </summary>
public static SidecarFrame WithProxy(SidecarFrame frame, bool proxied) => frame.Tier != DecodeTier.EmbeddedPreview
? frame
: frame with { Flags = proxied ? frame.Flags & ~FrameFlags.PreviewOnly : frame.Flags | FrameFlags.PreviewOnly };
private static int? Positive(int? value) => value > 0 ? value : null;
/// <summary>
@@ -117,7 +117,8 @@ public sealed record SidecarFrame
/// <summary>
/// Decode tier of the file (BRIEF §8.2) as the host that indexed or decoded it last found it; omitted until it is
/// known. <see cref="FrameFlags.PreviewOnly"/> and <see cref="FrameFlags.Undecodable"/> follow it.
/// known. <see cref="FrameFlags.PreviewOnly"/> (unless that host reads the frame from its proxy) and
/// <see cref="FrameFlags.Undecodable"/> follow it.
/// </summary>
[JsonConverter(typeof(TolerantEnumConverter<DecodeTier>))]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
+146 -34
View File
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using Titano.Core.Archiving;
using Titano.Core.Codecs.Jpeg;
@@ -10,7 +11,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
@@ -45,9 +48,26 @@ public sealed class ArchiveImages
private const int CommitFrames = 200;
private const int ProbeLongEdge = 64;
/// <summary>Proxy headers kept at most (<see cref="Headers"/>): some 30 MB, the proxies of a few large sequences.</summary>
private const int MaxHeaders = 1 << 17;
private static readonly TimeSpan CommitInterval = TimeSpan.FromSeconds(10);
/// <summary>
/// Age of a proxy file under which its header is not kept: a file system's clock may give a file written again at
/// once (with the same length) the same write time, at a granularity of up to two seconds.
/// </summary>
private static readonly TimeSpan Settling = TimeSpan.FromSeconds(3);
private static readonly ImageDecoder ServerDecoders = DecoderFactory.CreateServer();
/// <summary>
/// The capture time and size of proxies read lately, by path, while the file keeps its length and write time: the
/// server's manifests and tier records check every proxy of a sequence, so an unchanged one costs a stat.
/// </summary>
private static readonly ConcurrentDictionary<string, ProxyHeader> Headers = new(StringComparer.Ordinal);
private readonly TitanoDatabase _db;
private readonly SequenceWriter _writer;
private readonly ArchiveIndexer _indexer;
@@ -86,6 +106,21 @@ 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"/>, of <paramref name="width"/> × <paramref name="height"/>: its Exif capture
/// time is the frame's to the microsecond (the index's precision), or the frame has none to compare with; and, for a
/// frame whose original this host takes from its proxy (<paramref name="policy"/> given: the archive's), it is not
/// smaller than the policy's (<see cref="TooSmall"/>: one an earlier version made from an embedded preview). Proxies
/// are named by frame index, so one left by a frame renumbered since (frames inserted before it) is another photo's.
/// Renders, analyses, decode tiers and the server's manifests and downloads treat a proxy that fails this as missing,
/// and the proxy pass removes it (<see cref="BuildProxiesAsync"/>).
/// </summary>
/// <param name="policy">The archive's proxy policy for a frame whose original this host cannot decode (its proxy comes
/// from a client or render node); null for one this host decodes and makes the proxy of itself.</param>
public static bool IsProxyOf(string proxy, DateTime? capturedAt, int width, int height, ProxyPolicy? policy) =>
Check(proxy, capturedAt, width, height, policy).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
@@ -140,25 +175,30 @@ public sealed class ArchiveImages
if (frame.CapturedAt is { } captured)
{
using var stream = new MemoryStream(jpeg, writable: false);
if (MetadataReader.Read(stream, "proxy.jpg").CapturedAt != captured) return ProxyStoreResult.WrongFrame;
if (!SameCapture(MetadataReader.Read(stream, "proxy.jpg").CapturedAt, captured)) return ProxyStoreResult.WrongFrame;
}
var folder = paths.Sequence(sequence.Folder);
Directory.CreateDirectory(folder.Proxies);
AtomicFile.WriteAllBytes(folder.Proxy(frame.Index), jpeg);
var path = folder.Proxy(frame.Index);
AtomicFile.WriteAllBytes(path, jpeg);
Headers.TryRemove(path, out _);
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)
{
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
var policy = ManifestStore.ReadArchive(paths.ManifestPath).ThumbnailPolicy;
var archiveManifest = ManifestStore.ReadArchive(paths.ManifestPath);
var policy = archiveManifest.ThumbnailPolicy;
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 +206,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 +224,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)
&& Check(folder.Proxy(frame.I), frame.CapturedAt, frame.W, frame.H, archiveManifest.ProxyPolicy) is { Check: ProxyCheck.Current or ProxyCheck.Unverifiable } proxy)
fromProxy = !current || edge < System.Math.Min(policy.LongEdge, proxy.LongEdge);
if (current && !fromProxy)
{
reused++;
@@ -208,12 +254,18 @@ 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 _tiers.RecordAsync(archive, sequence, tiers, proxies: false, 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 +276,38 @@ 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 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);
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 check = Check(path, frame.CapturedAt, frame.W, frame.H, policy).Check;
var usable = check is ProxyCheck.Current or ProxyCheck.Unverifiable;
if (check == ProxyCheck.Stale) Delete(path);
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;
@@ -259,17 +316,19 @@ public sealed class ArchiveImages
() => _renderer.Proxy(folder, frame, manifest.Camera, policy, cancellationToken, companions.GetValueOrDefault(frame.Id))) is { } image)
{
AtomicFile.WriteAllBytes(path, image.Jpeg);
Headers.TryRemove(path, out _);
built++;
}
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, proxies: true, 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>
@@ -283,27 +342,80 @@ public sealed class ArchiveImages
/// <summary>The frame has no capture time to compare with.</summary>
Unverifiable,
/// <summary>Made from another frame (frames were renumbered since).</summary>
/// <summary>Made from another frame (frames were renumbered since), or too small (<see cref="Check"/>).</summary>
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>A proxy's Exif capture time and oriented long edge, read when the file had this length and write time.</summary>
private readonly record struct ProxyHeader(long Length, long WriteTicks, DateTime? CapturedAt, int LongEdge);
/// <summary>
/// Where the proxy at <paramref name="proxy"/> stands for the frame captured at <paramref name="capturedAt"/>, of
/// <paramref name="width"/> × <paramref name="height"/>, and its long edge: <see cref="ProxyCheck.Stale"/> also when
/// <paramref name="policy"/> is given and the proxy is <see cref="TooSmall"/> for it (<see cref="IsProxyOf"/>).
/// </summary>
private static (ProxyCheck Check, int LongEdge) Check(string proxy, DateTime? capturedAt, int width, int height, ProxyPolicy? policy)
{
var (check, longEdge) = ReadProxy(proxy, capturedAt);
if (check is ProxyCheck.Current or ProxyCheck.Unverifiable && policy is not null && TooSmall(longEdge, width, height, policy)) check = ProxyCheck.Stale;
return (check, longEdge);
}
/// <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 (ReadHeader(proxy) is not { } header) return (ProxyCheck.Missing, 0);
var check = capturedAt is not { } captured ? ProxyCheck.Unverifiable : SameCapture(header.CapturedAt, captured) ? ProxyCheck.Current : ProxyCheck.Stale;
return (check, header.LongEdge);
}
/// <summary>
/// The header of the proxy at <paramref name="proxy"/>; null when there is none or it cannot be read. Kept in
/// <see cref="Headers"/> while the file's length and write time stay as they were when it was read (taken first, so
/// a file replaced meanwhile is read again next time), once the file is older than <see cref="Settling"/>; a full
/// cache starts over.
/// </summary>
private static ProxyHeader? ReadHeader(string proxy)
{
if (!File.Exists(proxy)) return (ProxyCheck.Missing, 0);
try
{
var file = new FileInfo(proxy);
if (!file.Exists) return null;
var (length, written) = (file.Length, file.LastWriteTimeUtc);
if (Headers.TryGetValue(proxy, out var cached) && cached.Length == length && cached.WriteTicks == written.Ticks) return cached;
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;
return (check, System.Math.Max(width, height));
var header = new ProxyHeader(length, written.Ticks, metadata.CapturedAt, System.Math.Max(width, height));
if (DateTime.UtcNow - written < Settling)
{
Headers.TryRemove(proxy, out _);
return header;
}
if (Headers.Count >= MaxHeaders) Headers.Clear();
Headers[proxy] = header;
return header;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return (ProxyCheck.Missing, 0);
return null;
}
}
/// <summary>
/// Whether a proxy's Exif capture time is the frame's <paramref name="captured"/> to the microsecond: the index keeps
/// capture times to the microsecond, sidecars and Exif to the 100 ns tick, so a proxy made from either record of the
/// frame (here from the sidecar, by a client from the server's index) matches both.
/// </summary>
private static bool SameCapture(DateTime? proxy, DateTime captured) =>
proxy is { } time && time.Ticks / TimeSpan.TicksPerMicrosecond == captured.Ticks / TimeSpan.TicksPerMicrosecond;
/// <summary>Removes the proxy at <paramref name="path"/> and what is known of it.</summary>
private static void Delete(string path)
{
File.Delete(path);
Headers.TryRemove(path, out _);
}
/// <summary>
/// Whether a proxy whose long edge is <paramref name="longEdge"/> falls short of the policy's for a frame of
/// <paramref name="width"/> × <paramref name="height"/> (the policy's long edge, or the frame's own when smaller or
+27 -10
View File
@@ -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)
{
@@ -50,17 +52,25 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
}
/// <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.
/// Records <paramref name="tiers"/> (by frame id) where they change what the sidecar says, and returns the sequence's
/// frames as the sidecar has them afterwards (none when there was nothing to record). Frames no longer in the
/// sequence are ignored. The <see cref="FrameFlags.PreviewOnly"/> flag of a frame whose original this host reads
/// through its proxy follows whether its own proxy is there when the sidecar is written
/// (<see cref="ArchiveImages.IsProxyOf"/>, <see cref="SequenceFrames.WithProxy"/>), not when the caller looked: proxies
/// arrive while analyses and renders run, and another worker may have recorded them already.
/// </summary>
/// <param name="proxies">Whether every such frame follows its proxy even where no tier is recorded (analyses and the
/// proxy pass); otherwise only the frames in <paramref name="tiers"/> do.</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)
bool proxies, CancellationToken cancellationToken)
{
if (tiers.Count == 0) return [];
if (tiers.Count == 0 && !proxies) return [];
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
var folder = paths.Sequence(sequence.Folder);
var changed = new List<SidecarFrame>();
ProxyPolicy? policy = null;
var manifest = await writer.UpdateAsync(paths, sequence.Id, sequence.Folder, m =>
{
changed.Clear();
@@ -70,8 +80,16 @@ 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));
var tier = tiers.GetValueOrDefault(frame.Id);
if (tier is null && !proxies) continue;
bool? proxied = (frame.Flags & FrameFlags.Missing) == 0 && ArchiveImages.NeedsProxy(writer.Options.Decoder, frame.Format)
? ArchiveImages.IsProxyOf(folder.Proxy(frame.I), frame.CapturedAt, frame.W, frame.H,
policy ??= ManifestStore.ReadArchive(paths.ManifestPath).ProxyPolicy)
: null;
SidecarFrame updated;
if (tier is not null) updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format), proxied == true);
else if (proxied is { } own) updated = SequenceFrames.WithProxy(frame, own);
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;
@@ -86,14 +104,13 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
UpdatedAt = DateTimeOffset.UtcNow,
};
}, cancellationToken).ConfigureAwait(false);
if (changed.Count == 0) return [];
if (changed.Count == 0) return manifest.Frames;
await db.Frames.UpdateTiersAsync(changed.ConvertAll(f => new FrameTierFields(f.Id, f.Flags, f.PreviewW ?? 0, f.PreviewH ?? 0)), cancellationToken)
.ConfigureAwait(false);
var folder = paths.Sequence(sequence.Folder);
if (await db.Sequences.GetAsync(sequence.Id, cancellationToken).ConfigureAwait(false) is { } existing)
await db.Sequences.UpsertAsync(SequenceMapping.ToSequence(manifest, archive.Id, folder, existing), cancellationToken).ConfigureAwait(false);
await indexer.RecordStampsAsync(archive, folder, sequence.Id, cancellationToken).ConfigureAwait(false);
return changed;
return manifest.Frames;
}
/// <summary>
@@ -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);
}
}
+28
View File
@@ -0,0 +1,28 @@
using Titano.Core.Analysis.Deep;
using Titano.Core.Archiving;
using Titano.Core.Imaging;
using Titano.Core.Model;
namespace Titano.Data.Processing;
/// <summary>
/// Saved deep-analysis reports (<c>.titano/analysis.json</c>, BRIEF §10.2) for hosts that hand them on: a server serves
/// one to the editors of its clients only while it still describes the sequence (§14.5).
/// </summary>
public static class DeepReports
{
/// <summary>
/// The saved report of <paramref name="sequence"/> when it describes its frames as a host with
/// <paramref name="decoder"/> reads them now; null when there is none, it covers another number of frames, or it
/// found unreadable a frame that has been read from its proxy since (an original that host cannot decode, whose proxy
/// arrived after the analysis): its verdict and its advice to exclude that frame no longer hold.
/// </summary>
public static async Task<DeepAnalysisReport?> ReadCurrentAsync(TitanoDatabase db, Archive archive, Sequence sequence, ImageDecoder decoder,
CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(archive);
ArgumentNullException.ThrowIfNull(sequence);
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, decoder, cancellationToken).ConfigureAwait(false);
return SequenceAnalyser.ReadReport(new ArchivePaths(archive.RootPath).Sequence(sequence.Folder), frames);
}
}
@@ -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(
@@ -94,11 +94,12 @@ internal sealed class RenderJobHandler(TitanoDatabase db, ProcessingOptions opti
if (render.StandIns.Count > 0)
context.Log(Loc.L("Export.Log.StandIns", string.Join(", ", render.StandIns.Select(i => (i + 1).ToString(Loc.Culture)))));
// Recorded without the job's token: what decoding found holds even if the job is cancelled meanwhile, and a
// sidecar that cannot be written now only leaves it to the next analysis or render.
// sidecar that cannot be written now only leaves it to the next analysis or render. A frame decoded from its
// preview whose proxy arrived during the render is not preview-only: FrameTiers looks for the proxy as it records.
try
{
var decoded = render.Decoded.ToDictionary(kv => frames.Frames[kv.Key].Id, kv => kv.Value);
await tiers.RecordAsync(archive, sequence, decoded, CancellationToken.None).ConfigureAwait(false);
await tiers.RecordAsync(archive, sequence, decoded, proxies: false, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or LeaseUnavailableException
or ArchiveOfflineException)
+44 -13
View File
@@ -45,21 +45,24 @@ 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); the
// flags are taken as the sidecar has them once recorded, so ones another worker recorded meanwhile count too.
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));
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, proxies: true, cancellationToken).ConfigureAwait(false));
var metadata = frames.LightFrames();
DeepAnalysisReport? report;
if (deep)
{
// Proxies may have arrived during the pass: the advice below follows the frames as they are at its end.
(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, proxies: true, 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 +88,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 +106,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;
@@ -119,11 +140,11 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
}
}
/// <summary>The frame rows with the tier fields of <paramref name="changed"/> sidecar frames.</summary>
private static SequenceFrames WithTiers(SequenceFrames frames, IReadOnlyList<SidecarFrame> changed)
/// <summary>The frame rows with the flags and preview sizes of the <paramref name="current"/> sidecar frames.</summary>
private static SequenceFrames WithTiers(SequenceFrames frames, IReadOnlyList<SidecarFrame> current)
{
if (changed.Count == 0) return frames;
var byId = changed.ToDictionary(f => f.Id);
if (current.Count == 0) return frames;
var byId = current.ToDictionary(f => f.Id);
var rows = frames.Frames.Select(f => byId.TryGetValue(f.Id, out var s)
? f with { Flags = s.Flags, PreviewWidth = s.PreviewW ?? 0, PreviewHeight = s.PreviewH ?? 0 }
: f).ToList();
@@ -179,6 +200,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 +215,18 @@ 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>
private static string ContentKey(SequenceFrames frames)
/// 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. Only frames read from proxies are marked, so the key of a sequence read
/// from its originals is what it was before proxies counted, and checkpoints written then still resume.</summary>
internal 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" : "";
hash.AppendData(Encoding.UTF8.GetBytes($"{f.Id:N}/{f.Sha256}/{f.Size}/{f.Flags & SequenceFrames.NotAnalysed}{source};"));
}
return Convert.ToHexStringLower(hash.GetHashAndReset())[..16];
}
+8 -3
View File
@@ -34,7 +34,9 @@ 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, nor, for an original this host cannot decode, one smaller
/// than the archive's policy); else the original.
/// </summary>
public static async Task<SequenceFrames> LoadAsync(TitanoDatabase db, Archive archive, Sequence sequence, bool useProxies, ImageDecoder decoder,
CancellationToken cancellationToken)
@@ -45,13 +47,16 @@ internal sealed record SequenceFrames(Sequence Sequence, IReadOnlyList<Frame> Fr
var files = new string?[frames.Count];
var originals = new string?[frames.Count];
var proxied = new bool[frames.Count];
ProxyPolicy? policy = null;
for (var i = 0; i < files.Length; i++)
{
var frame = frames[i];
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);
var needs = ArchiveImages.NeedsProxy(decoder, frame.Format);
var proxy = useProxies || needs ? folder.Proxy(frame.Index) : null;
proxied[i] = proxy is not null && ArchiveImages.IsProxyOf(proxy, frame.CapturedAt, frame.Width, frame.Height,
needs ? policy ??= ManifestStore.ReadArchive(paths.ManifestPath).ProxyPolicy : null);
files[i] = proxied[i] ? proxy : originals[i];
}
return new SequenceFrames(sequence, frames, files) { Proxied = proxied, Originals = originals };
+2 -2
View File
@@ -60,8 +60,8 @@ public static class FileEndpoints
/// <summary>
/// Files the body (a JPEG made from the original, its Exif capture time the frame's, as large as the archive's proxies,
/// at most <see cref="ArchiveImages.MaxProxyBytes"/>) as the proxy of a frame the server cannot decode
/// (<see cref="ServerProxies"/>); the sequence's thumbnails and proxy state follow as background jobs. 204; 413
/// <c>too_large</c>; 422 <c>proxy_not_wanted</c> (the server decodes that original itself, or it is missing or
/// (<see cref="ServerProxies"/>); the sequence's thumbnails, proxy state and light analysis follow as background jobs.
/// 204; 413 <c>too_large</c>; 422 <c>proxy_not_wanted</c> (the server decodes that original itself, or it is missing or
/// damaged), <c>invalid_proxy</c>, <c>proxy_mismatch</c> or <c>proxy_too_small</c>, which concern that proxy only; 409
/// <c>proxies_disabled</c>, which concerns them all; 503 <c>archive_offline</c>.
/// </summary>
+15 -1
View File
@@ -254,7 +254,11 @@ public static class SequenceEndpoints
_ => ApiErrors.NotFound(context, "analysis"),
};
/// <summary>The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence.</summary>
/// <summary>
/// The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence, while it
/// describes the frames as the server reads them now (<see cref="DeepReports.ReadCurrentAsync"/>): one that found
/// frames unreadable before their proxies arrived answers 404 <c>analysis</c>, so no editor advises excluding them.
/// </summary>
private static async Task<IResult> ReportAsync(HttpContext context, Guid id, TitanoDatabase db, ServerArchive archive)
{
if (await db.Sequences.GetAsync(id, context.RequestAborted) is not { } sequence) return ApiErrors.NotFound(context, "sequence");
@@ -262,6 +266,16 @@ public static class SequenceEndpoints
var path = new Core.Archiving.ArchivePaths(archive.Root).Sequence(sequence.Folder).AnalysisPath;
var file = new FileInfo(path);
if (!file.Exists || file.LinkTarget is not null || !ArchivePathGuard.IsInside(archive.Root, path)) return ApiErrors.NotFound(context, "analysis");
try
{
if (await DeepReports.ReadCurrentAsync(db, archive.Current, sequence, Core.Imaging.Decoders.DecoderFactory.CreateServer(), context.RequestAborted) is null)
return ApiErrors.NotFound(context, "analysis");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
{
// archive.json cannot be read now, so whether the proxies count is not known.
return ApiErrors.NotFound(context, "analysis");
}
var etag = string.Create(CultureInfo.InvariantCulture, $"a-{file.Length}-{file.LastWriteTimeUtc.Ticks}");
return FileResponses.Serve(context, file, 0, file.Length, "application/json; charset=utf-8", "no-cache", etag) ?? ApiErrors.NotFound(context, "analysis");
}
+3 -2
View File
@@ -5,13 +5,14 @@ namespace Titano.Server.Jobs;
/// <summary>
/// Follow-up work after frames arrive (BRIEF §14.4): thumbnails, proxies and light analysis of the sequence; after a
/// proxy sent by a client or render node arrives, the thumbnails and the sequence's proxy state. Queued at background
/// proxy sent by a client or render node arrives, the thumbnails, the sequence's proxy state and the light analysis (a
/// frame read from its proxy is no longer preview-only, so the advisor's Auto values change). Queued at background
/// priority once per sequence while one is still waiting, and only for kinds this server can run.
/// </summary>
public sealed class SequenceJobs(TitanoDatabase db, JobEngineHost jobs)
{
private static readonly JobKind[] AfterNewFrames = [JobKind.Thumbs, JobKind.Proxies, JobKind.LightAnalyse];
private static readonly JobKind[] AfterProxy = [JobKind.Thumbs, JobKind.Proxies];
private static readonly JobKind[] AfterProxy = [JobKind.Thumbs, JobKind.Proxies, JobKind.LightAnalyse];
private readonly SemaphoreSlim _gate = new(1, 1);
@@ -1,12 +1,14 @@
using Titano.Core.Archiving;
using Titano.Core.Model;
using Titano.Data.Archiving;
namespace Titano.Server.Storage;
/// <summary>
/// Proxies are files under the sequence's <c>proxies/</c> folder; a thumbnail is the JPEG byte range of its entry in
/// <c>thumbs.pack</c>. A thumbnail made from a different original (the frame was renumbered or replaced) counts as not
/// built yet, like a missing one.
/// built yet, like a missing one, and so does a proxy whose capture time is another frame's, or one smaller than the
/// archive's policy sent for a frame the server cannot decode (<see cref="ServerProxies.HasProxy"/>).
/// </summary>
internal sealed class ArchiveAssetLocator : IFrameAssetLocator
{
@@ -15,13 +17,17 @@ internal sealed class ArchiveAssetLocator : IFrameAssetLocator
public ValueTask<AssetLocation?> LocateAsync(Archive archive, Sequence sequence, Frame frame, FrameAsset asset, CancellationToken cancellationToken)
{
var paths = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder);
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(paths, frame) : Thumbnail(paths, frame));
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(archive, paths, frame) : Thumbnail(paths, frame));
}
private static AssetLocation? Proxy(SequencePaths paths, Frame frame)
private static AssetLocation? Proxy(Archive archive, SequencePaths paths, Frame frame)
{
var file = new FileInfo(paths.Proxy(frame.Index));
return file.Exists ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
if (!file.Exists) return null;
var own = ServerProxies.CannotDecode(frame.Format)
? ServerProxies.HasProxy(paths, frame, ServerProxies.Spec(archive))
: ArchiveImages.IsProxyOf(file.FullName, frame.CapturedAt, frame.Width, frame.Height, policy: null);
return own ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
}
private static AssetLocation? Thumbnail(SequencePaths paths, Frame frame)
+18 -6
View File
@@ -34,9 +34,20 @@ public static class ServerProxies
}
/// <summary>
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it: a proxy is there when the server
/// built them all or one was sent for the frame; it is wanted for a frame the server cannot decode that has none
/// (and is not missing), unless <paramref name="spec"/> is null.
/// Whether the proxy of <paramref name="frame"/>, one the server cannot decode, is in <paramref name="folder"/>: the
/// frame's own (<see cref="ArchiveImages.IsProxyOf"/>: one left at its index by a frame renumbered since is another
/// photo's) and as large as <paramref name="spec"/> asks (null: the archive makes none, or its manifest cannot be read
/// now, so the size is not judged).
/// </summary>
public static bool HasProxy(SequencePaths folder, Frame frame, ProxySpec? spec) =>
ArchiveImages.IsProxyOf(folder.Proxy(frame.Index), frame.CapturedAt, frame.Width, frame.Height,
spec is null ? null : new ProxyPolicy { LongEdge = spec.LongEdge, Quality = spec.Quality });
/// <summary>
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it. A frame the server cannot decode
/// has its proxy when its own is there (<see cref="HasProxy"/>), whatever the sequence's built status says (frames
/// added or renumbered since keep it until the next proxy pass), and wants one otherwise (unless it is missing or
/// damaged, or <paramref name="spec"/> is null); any other frame has one when the server built them all.
/// </summary>
public static async Task<List<ManifestFrame>> FramesAsync(TitanoDatabase db, Archive archive, Sequence sequence, ProxySpec? spec,
CancellationToken cancellationToken)
@@ -51,9 +62,10 @@ public static class ServerProxies
var batch = await db.Frames.ListBySequenceAsync(sequence.Id, after, Page, cancellationToken);
foreach (var f in batch)
{
var sent = !proxies && CannotDecode(f.Format) && File.Exists(folder.Proxy(f.Index));
var wanted = spec is not null && !proxies && !sent && CannotDecode(f.Format) && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, proxies || sent, thumbs, (long)f.Flags, wanted));
var elsewhere = CannotDecode(f.Format);
var has = elsewhere ? HasProxy(folder, f, spec) : proxies;
var wanted = spec is not null && elsewhere && !has && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, has, thumbs, (long)f.Flags, wanted));
}
if (batch.Count < Page) return frames;
after = batch[^1].Index;