E3: API di formati e fotogrammi, conversione della libreria e demo
Porta le funzioni della tappa E3 fino all'interfaccia web, così che WP4 possa costruire le schermate su indirizzi veri. - Impostazioni, cartelle delle copie e «Copia in…» hanno i formati (nomi original, jpg, png, webplossless, mp4); il riepilogo dice cosa si converte, cosa resta com'è e se c'è perdita. «Copia di nuovo» rifà la copia nella sua forma esatta. - Fotogrammi: informazioni di un video, un fotogramma (anteprima o scaricamento), gli istanti di una modalità, «Scarica» di uno o di uno zip scritto mentre parte, con il permesso dei lavori lunghi oltre 20. Kestrel non vede mai scritture sincrone: il piccolo descrittore che lo zip di .NET 10 scrive in modo sincrono parte con la scrittura seguente. - Conversione della libreria: stato, la domanda «Converti anche i N già in libreria?», riprova, pausa e ripresa; il visualizzatore mostra i file convertiti, e le eliminazioni li contano. - Demo: un video H.264 scritto in casa (solo macroblocchi I_PCM) per ogni video, una copia in PNG, un fotogramma e due conversioni; la conversione non parte mai. Due prove cambiano con il comportamento: i video della demo ora si aprono, e un file non copiato può avere il segno «solo fotogramma». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
724c5bda6f
commit
ab0d717424
25 files changed
+2559
-95
No files matched your search
@@ -0,0 +1,82 @@
|
||||
using System.IO.Compression;
|
||||
using Febe.Core.Codecs.H264;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
using Febe.Tests.Support;
|
||||
using Febe.Web.Export;
|
||||
|
||||
namespace Febe.Tests.Web;
|
||||
|
||||
/// <summary>
|
||||
/// The zip of «Scarica» of frames (tappa E3, D14): written while it is sent, through asynchronous writes only (a
|
||||
/// response body refuses synchronous ones), one entry per frame under the account folder, names made unique.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class FrameServiceTests
|
||||
{
|
||||
public TestContext TestContext { get; set; } = null!;
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheZipIsWrittenThroughAsynchronousWritesOnly()
|
||||
{
|
||||
using var temp = new TempFolder("fotogrammi-zip");
|
||||
var path = temp.Combine("video.mp4");
|
||||
await File.WriteAllBytesAsync(path, H264PcmWriter.DemoVideo(), TestContext.CancellationToken);
|
||||
var clock = new ManualClock(Make.T0);
|
||||
var service = new FrameService(clock);
|
||||
var instants = new[] { TimeSpan.Zero, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1.5) };
|
||||
var plan = new FrameDownloadPlan(FrameMode.Count, ExportFormat.Png, [
|
||||
new FrameDownloadVideo("marta.demo", path, "post", instants, Make.T0.AddDays(-3)),
|
||||
new FrameDownloadVideo("marta.demo", path, "post", instants[..1], Make.T0.AddDays(-3)),
|
||||
]);
|
||||
using var sent = new MemoryStream();
|
||||
|
||||
await service.WriteZipAsync(new AsyncOnlyStream(sent), plan, publicationTime: true, TestContext.CancellationToken);
|
||||
|
||||
using var archive = new ZipArchive(new MemoryStream(sent.ToArray()), ZipArchiveMode.Read);
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "marta.demo/post_f001.png", "marta.demo/post_f002.png", "marta.demo/post_f003.png", "marta.demo/post_f001 (2).png" },
|
||||
archive.Entries.Select(e => e.FullName).ToArray());
|
||||
var published = TimeZoneInfo.ConvertTime(Make.T0.AddDays(-3), clock.LocalZone).DateTime;
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
Assert.AreEqual(entry.Length, entry.CompressedLength, "frames are stored, not compressed");
|
||||
// The zip keeps local date and time fields at 2 s steps: the time of publication where Febe runs (D18).
|
||||
Assert.IsLessThanOrEqualTo(2.0, Math.Abs((entry.LastWriteTime.DateTime - published).TotalSeconds), $"{entry.LastWriteTime} vs {published}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A response body: asynchronous writes only.</summary>
|
||||
private sealed class AsyncOnlyStream(Stream inner) : Stream
|
||||
{
|
||||
public override bool CanRead => false;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override long Length => throw new NotSupportedException();
|
||||
|
||||
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
|
||||
|
||||
public override void Flush() => throw new InvalidOperationException("synchronous flush");
|
||||
|
||||
public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) => throw new InvalidOperationException("synchronous write");
|
||||
|
||||
public override void Write(ReadOnlySpan<byte> buffer) => throw new InvalidOperationException("synchronous write");
|
||||
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
|
||||
inner.WriteAsync(buffer, offset, count, cancellationToken);
|
||||
|
||||
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) =>
|
||||
inner.WriteAsync(buffer, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user