fix(analysis): a deep run checks its report against the frames as they are when it records
A deep analysis kept the report it had just made, measured from the frames loaded at its start. Proxies that arrived during a long run make its verdict on those frames' originals stale (every later reader drops the report), yet the run applied its advice and recorded AnalyzedDeep, HasWarnings and the unreadable frames' warnings. The light analysis the proxies queued could have finished on another worker before, and nothing ran it again. The run now loads the frames again under the sequence lock and keeps its report only while it describes them (SequenceAnalyser.ReadReport's rule); the Auto values are applied under that same lock as the status (ProjectStore.UpdateLockedAsync), so a light analysis either ran before and is not undone, or runs after. Its scan stamps are recorded only while the index holds the sidecar's frames. Test: a deep analysis of HEIF files without an Exif thumbnail, during which their proxies arrive, records no deep status and leaves the warnings and Auto values of the light analysis that read the proxies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+124
-52
No files matched your search
@@ -14,13 +14,17 @@ namespace Titano.Data.Tests.Archiving;
|
||||
internal static class HeifFile
|
||||
{
|
||||
/// <summary>A <paramref name="width"/> × <paramref name="height"/> HEIF captured at <paramref name="captured"/>, its Exif
|
||||
/// thumbnail <paramref name="thumbnailWidth"/> × <paramref name="thumbnailHeight"/>.</summary>
|
||||
/// thumbnail <paramref name="thumbnailWidth"/> × <paramref name="thumbnailHeight"/> (none when the width is 0: such a
|
||||
/// host finds no pixels in it at all).</summary>
|
||||
public static byte[] Create(DateTime captured, int width, int height, int thumbnailWidth = 160, int thumbnailHeight = 120)
|
||||
{
|
||||
using var small = new ImageBuffer(thumbnailWidth, thumbnailHeight);
|
||||
for (var c = 0; c < 3; c++) small.Plane(c).Fill(0.2f + c * 0.2f);
|
||||
var thumbnail = JpegEncoder.Encode(small, new JpegEncodeOptions { Quality = 80 });
|
||||
var tiff = WithThumbnail(ExifWriter.BuildTiff(new FrameMetadata { Make = "TestCam", Model = "H-1", CapturedAt = captured }), thumbnail);
|
||||
var tiff = ExifWriter.BuildTiff(new FrameMetadata { Make = "TestCam", Model = "H-1", CapturedAt = captured });
|
||||
if (thumbnailWidth > 0)
|
||||
{
|
||||
using var small = new ImageBuffer(thumbnailWidth, thumbnailHeight);
|
||||
for (var c = 0; c < 3; c++) small.Plane(c).Fill(0.2f + c * 0.2f);
|
||||
tiff = WithThumbnail(tiff, JpegEncoder.Encode(small, new JpegEncodeOptions { Quality = 80 }));
|
||||
}
|
||||
byte[] exif = [.. U32(6), .. "Exif\0\0"u8, .. tiff];
|
||||
// The HEVC-coded primary image, which no managed decoder reads.
|
||||
var coded = new byte[64];
|
||||
|
||||
@@ -206,6 +206,54 @@ public sealed class AnalysisJobTests(TestContext context)
|
||||
Assert.Equal("4k-hevc", await PresetAsync());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProxiesThatArriveDuringADeepAnalysisOfHeifsWithoutThumbnailsMakeItsUnreadableVerdictStale()
|
||||
{
|
||||
// A server, which finds no pixels at all in these HEIF files (they carry no Exif thumbnail) until proxies come (BRIEF §2.3).
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context, o => o with { Host = EncoderHost.Server });
|
||||
var directory = Path.Combine(fx.Archive.Paths.Root, "Heif");
|
||||
Directory.CreateDirectory(directory);
|
||||
var start = new DateTime(2026, 9, 28, 18, 0, 0);
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
await File.WriteAllBytesAsync(Path.Combine(directory, $"IMG_{i + 1:0000}.HEIC"), HeifFile.Create(start.AddSeconds(10 * i), 4032, 3024, thumbnailWidth: 0),
|
||||
fx.Ct);
|
||||
}
|
||||
await fx.Archive.ScanAsync(ScanMode.Full);
|
||||
var location = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Archive.Id, fx.Ct)).Single(l => l.Folder == "Heif");
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(location.Id, fx.Ct))!;
|
||||
var folder = fx.Folder(sequence);
|
||||
await fx.StartEngineAsync(workers: 2);
|
||||
async Task<string> AutoValuesAsync() =>
|
||||
File.Exists(folder.ProjectPath) ? ProjectSettings.FromJson(await File.ReadAllTextAsync(folder.ProjectPath, fx.Ct)).ToJson() : string.Empty;
|
||||
|
||||
// A deep analysis starts on the originals; while it runs, the proxies arrive and a light analysis on the other
|
||||
// worker reads the frames from them.
|
||||
fx.Decoder.Hold = "IMG_0001.HEIC";
|
||||
var deep = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
|
||||
Directory.CreateDirectory(folder.Proxies);
|
||||
foreach (var frame in await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))
|
||||
await File.WriteAllBytesAsync(folder.Proxy(frame.Index), Proxy(frame.CapturedAt!.Value, 1920, 1440), fx.Ct);
|
||||
await LightAnalysisAsync(fx, sequence);
|
||||
var light = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
|
||||
var advice = await AutoValuesAsync();
|
||||
fx.Decoder.Release();
|
||||
await fx.WaitForAsync(deep.Id, JobState.Done);
|
||||
|
||||
// The deep pass found no pixels in any original, a verdict the proxies made stale before it ended, as every reader
|
||||
// of its report finds: it records no deep status, and neither warnings nor advice of its own.
|
||||
Assert.Count(4, SequenceAnalyser.ReadReport(folder, sequence.FrameCount)!.Issues.Undecodable);
|
||||
var now = await Titano.Data.Processing.SequenceFrames.LoadAsync(fx.Db, fx.Archive.Archive, sequence, useProxies: false,
|
||||
new ImageDecoder([fx.Decoder]), fx.Ct);
|
||||
Assert.Null(SequenceAnalyser.ReadReport(folder, now));
|
||||
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
|
||||
Assert.False(row.Status.HasFlag(SequenceStatus.AnalyzedDeep), row.Status.ToString());
|
||||
Assert.False(ManifestStore.ReadSequence(folder.ManifestPath).Status.HasFlag(SequenceStatus.AnalyzedDeep), "sidecar status");
|
||||
Assert.Equal((light.WarningCount, light.Status.HasFlag(SequenceStatus.HasWarnings)), (row.WarningCount, row.Status.HasFlag(SequenceStatus.HasWarnings)));
|
||||
Assert.Equal(advice, await AutoValuesAsync());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFrameTheDeepAnalysisCouldNotReadIsReadAgainOnceItsProxyArrives()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user