E3: seconda revisione di rimuxaggio, spazio, impostazioni e zip
verifica / controlli (push) Canceled after 0s
verifica / prove (push) Canceled after 0s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

Le quattro osservazioni confermate della seconda revisione, ognuna con
la sua prova (ciascuna cade sul codice di prima):

- Rimuxaggio con fotogrammi B: l'MP4 misura la fine della presentazione
  in tempo di composizione, non con la somma delle durate di decodifica.
  Prima nascondeva gli ultimi fotogrammi mostrati (2 in un iPhone) e
  durava altrettanto meno in elst, tkhd e mvhd. Per le tracce senza
  scarti di composizione i byte restano gli stessi.
- Conversione della libreria: il lavoro ricorda il file che l'ha messo
  in pausa per spazio e quanto serve al suo convertito. Finché il disco
  non ha posto anche per quello, non rilegge l'originale a ogni
  risveglio (anche quando lo spazio libero sta appena sopra la soglia).
- Impostazioni dell'esportazione: formati, chiavi «dal» e coda del
  formato sostituito si salvano in una transazione sola; «Anche i N»
  dopo il salvataggio non dipende più dalla richiesta. Il gancio della
  libreria legge formati e chiavi «dal» in una lettura. Una scheda
  chiusa o un arresto non lasciano più un formato senza la sua chiave
  né «Non riuscito» che «Riprova» non tocca.
- Zip dei fotogrammi: i tempi del blocco passano da un TimeProvider
  della BCL, e la prova del lettore lento non dipende più dal carico
  della macchina.

Decisioni in docs/decisioni.md (28/11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-28 14:29:00 +01:00
1 parent 958cb71cd6
commit 2efb408957
13 files changed
+459 -49

No files matched your search

+100 -5
View File
@@ -54,14 +54,17 @@ public sealed class FrameServiceTests
using var temp = new TempFolder("fotogrammi-lento");
var path = temp.Combine("rumore.mp4");
await File.WriteAllBytesAsync(path, NoiseVideo(), ct);
var service = new FrameService(new ManualClock(Make.T0)) { WriteStall = TimeSpan.FromMilliseconds(400) };
// The time of the stalls moves only as the link sends, never with the load of the machine.
var time = new LinkTime();
var service = new FrameService(new ManualClock(Make.T0)) { WriteStall = TimeSpan.FromMilliseconds(400), StallTime = time };
var plan = new FrameDownloadPlan(FrameMode.At, ExportFormat.Png, [
new FrameDownloadVideo("marta.demo", path, "rumore", [TimeSpan.Zero], Make.T0),
]);
// 64 KB every 150 ms: a frame of a few hundred KB takes longer than the 400 ms of a stall, but every piece goes.
using var sent = new MemoryStream();
var link = new SlowStream(sent, TimeSpan.FromMilliseconds(150));
var link = new SlowStream(sent, TimeSpan.FromMilliseconds(150), time);
await service.WriteZipAsync(link, plan, publicationTime: false, ct);
using var archive = new ZipArchive(new MemoryStream(sent.ToArray()), ZipArchiveMode.Read);
@@ -113,9 +116,10 @@ public sealed class FrameServiceTests
/// <summary>
/// A response body on a slow link: asynchronous writes only, each taking <c>perPiece</c> for every 64 KB it holds
/// (a write completes once its bytes are sent); an infinite time is a reader that stopped.
/// (a write completes once its bytes are sent); an infinite time is a reader that stopped. With a
/// <see cref="LinkTime"/> a write moves that time instead of waiting for the real one.
/// </summary>
private sealed class SlowStream(Stream inner, TimeSpan perPiece) : Stream
private sealed class SlowStream(Stream inner, TimeSpan perPiece, LinkTime? time = null) : Stream
{
public TimeSpan Busy { get; private set; }
@@ -149,7 +153,16 @@ public sealed class FrameServiceTests
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
var wait = perPiece == Timeout.InfiniteTimeSpan ? Timeout.InfiniteTimeSpan : perPiece * ((buffer.Length + 65535) / 65536);
await Task.Delay(wait, cancellationToken);
if (time is not null && wait != Timeout.InfiniteTimeSpan)
{
time.Advance(wait); // the stall timers due before this write is sent fire now
cancellationToken.ThrowIfCancellationRequested();
}
else
{
await Task.Delay(wait, cancellationToken);
}
if (wait != Timeout.InfiniteTimeSpan)
{
Busy += wait;
@@ -159,6 +172,88 @@ public sealed class FrameServiceTests
}
}
/// <summary>
/// A time that moves only when <see cref="Advance"/> is called: its timers fire then, in order, on the caller's
/// thread. Only one-shot timers (those of a <see cref="CancellationTokenSource"/>) are supported.
/// </summary>
private sealed class LinkTime : TimeProvider
{
private readonly Lock _gate = new();
private readonly List<LinkTimer> _timers = [];
private DateTimeOffset _now = Make.T0;
public override DateTimeOffset GetUtcNow()
{
lock (_gate)
{
return _now;
}
}
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
Assert.AreEqual(Timeout.InfiniteTimeSpan, period, "one-shot timers only");
var timer = new LinkTimer(this, callback, state);
timer.Change(dueTime, period);
return timer;
}
public void Advance(TimeSpan by)
{
List<LinkTimer> due;
lock (_gate)
{
_now += by;
due = [.. _timers.Where(t => t.Due <= _now).OrderBy(t => t.Due)];
foreach (var t in due)
{
_timers.Remove(t);
}
}
foreach (var t in due)
{
t.Fire();
}
}
private sealed class LinkTimer(LinkTime owner, TimerCallback callback, object? state) : ITimer
{
public DateTimeOffset Due { get; private set; }
public bool Change(TimeSpan dueTime, TimeSpan period)
{
lock (owner._gate)
{
owner._timers.Remove(this);
if (dueTime != Timeout.InfiniteTimeSpan)
{
Due = owner._now + dueTime;
owner._timers.Add(this);
}
}
return true;
}
public void Fire() => callback(state);
public void Dispose()
{
lock (owner._gate)
{
owner._timers.Remove(this);
}
}
public ValueTask DisposeAsync()
{
Dispose();
return ValueTask.CompletedTask;
}
}
}
/// <summary>A response body: asynchronous writes only.</summary>
private sealed class AsyncOnlyStream(Stream inner) : Stream
{