feat(server): render MP4 jobs no render node can take as MJPEG, and say so
BRIEF §14.7: the server falls back to managed formats when no node is available and says so in the job log. An MP4 job waits for render nodes at least the node timeout, then as long as an online node can encode its codec at its size; after that the server's engine takes it and writes each output it cannot encode as MJPEG in AVI at the same size and frame rate, with a job log line. A job the server started resumes there. Selective acceptance is asynchronous for that; when node availability cannot be read the job keeps waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
15 files changed
+247
-48
No files matched your search
@@ -23,16 +23,17 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
|
||||
private JobEngine? _engine;
|
||||
|
||||
private ProcessingFixture(ArchiveFixture archive, GateDecoder decoder)
|
||||
private ProcessingFixture(ArchiveFixture archive, GateDecoder decoder, Func<ProcessingOptions, ProcessingOptions>? configure)
|
||||
{
|
||||
Archive = archive;
|
||||
Decoder = decoder;
|
||||
Processing = new ProcessingService(archive.Db, new ProcessingOptions
|
||||
var options = new ProcessingOptions
|
||||
{
|
||||
Archive = new ArchiveServiceOptions { Decoder = new ImageDecoder([decoder]), Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) },
|
||||
DeepAnalysis = DeepOptions,
|
||||
ProducedBy = "test-pc",
|
||||
});
|
||||
};
|
||||
Processing = new ProcessingService(archive.Db, configure?.Invoke(options) ?? options);
|
||||
}
|
||||
|
||||
public ArchiveFixture Archive { get; }
|
||||
@@ -43,7 +44,9 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
|
||||
public JobEngine Engine => _engine ?? throw new InvalidOperationException("Start the engine first.");
|
||||
|
||||
public static async Task<ProcessingFixture> CreateAsync(TestContext context) => new(await ArchiveFixture.CreateAsync(context), new GateDecoder());
|
||||
/// <param name="configure">Changes to the processing options (a server's host and render-node check).</param>
|
||||
public static async Task<ProcessingFixture> CreateAsync(TestContext context, Func<ProcessingOptions, ProcessingOptions>? configure = null) =>
|
||||
new(await ArchiveFixture.CreateAsync(context), new GateDecoder(), configure);
|
||||
|
||||
/// <summary>A started engine with the processing handlers, and the archive's when asked (one worker unless asked, fast checkpoints).</summary>
|
||||
public async Task<JobEngine> StartEngineAsync(bool withArchive = false, int workers = 1)
|
||||
|
||||
@@ -26,6 +26,9 @@ public sealed class RenderJobTests(TestContext context)
|
||||
NameTemplate = "clip-{codec}",
|
||||
};
|
||||
|
||||
/// <summary>HEVC (a render node's codec) at the size of <see cref="Mjpeg"/>.</summary>
|
||||
private static readonly ExportSettings Hevc = Mjpeg with { Preset = new Auto<string>().WithManual("4k-hevc") };
|
||||
|
||||
private static SyntheticSequence Scene() => SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = Frames, StartEv = 0.5, EndEv = -0.5 });
|
||||
|
||||
[Test]
|
||||
@@ -214,25 +217,62 @@ public sealed class RenderJobTests(TestContext context)
|
||||
public async Task AServerTakesOnlyTheRendersItsManagedEncodersProduce()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var server = new ProcessingService(fx.Db, new ProcessingOptions { Host = EncoderHost.Server });
|
||||
var server = new ProcessingService(fx.Db, new ProcessingOptions { Host = EncoderHost.Server, AwaitsRenderNode = (_, _, _) => Task.FromResult(true) });
|
||||
var handler = Assert.NotNull(server.CreateJobHandlers().Single(h => h.Kind == JobKind.Render) as ISelectiveJobHandler);
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic" };
|
||||
bool Accepts(ExportSettings export) =>
|
||||
handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = ProcessingJobs.Render(sequence, export, 96, 64).ParametersJson });
|
||||
Job Job(ExportSettings export) => new() { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = ProcessingJobs.Render(sequence, export, 96, 64).ParametersJson };
|
||||
async Task<bool> AcceptsAsync(string? parametersJson) =>
|
||||
await handler.AcceptsAsync(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = parametersJson }, fx.Ct);
|
||||
|
||||
Assert.True(Accepts(Mjpeg with { Batch = ["png-sequence", "gif-preview"] }), "managed outputs only");
|
||||
Assert.False(Accepts(new ExportSettings { Preset = new Auto<string>().WithManual("4k-hevc") }), "HEVC needs a render node");
|
||||
Assert.False(Accepts(Mjpeg with { Batch = ["1080p-h264"] }), "one MP4 in the batch");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = "{}" }), "unreadable: fails with its reason");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = WithPreset("""{"preset":{},"Preset":{}}""") }),
|
||||
"a member given twice: fails with its reason");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = WithPreset("""{"preset":{"isAuto":false,"manual":"mjpeg-avi"},"batch":null}""") }),
|
||||
"a null batch is no batch");
|
||||
Assert.True(await handler.AcceptsAsync(Job(Mjpeg with { Batch = ["png-sequence", "gif-preview"] }), fx.Ct), "managed outputs only");
|
||||
Assert.False(await handler.AcceptsAsync(Job(Hevc), fx.Ct), "HEVC waits for a render node");
|
||||
Assert.False(await handler.AcceptsAsync(Job(Mjpeg with { Batch = ["1080p-h264"] }), fx.Ct), "one MP4 in the batch");
|
||||
Assert.True(await handler.AcceptsAsync(Job(Hevc) with { Checkpoint = """{"done":[],"pending":0}""" }, fx.Ct), "started here: resumes here");
|
||||
Assert.True(await AcceptsAsync("{}"), "unreadable: fails with its reason");
|
||||
Assert.True(await AcceptsAsync(WithPreset("""{"preset":{},"Preset":{}}""")), "a member given twice: fails with its reason");
|
||||
Assert.True(await AcceptsAsync(WithPreset("""{"preset":{"isAuto":false,"manual":"mjpeg-avi"},"batch":null}""")), "a null batch is no batch");
|
||||
|
||||
var client = new ProcessingService(fx.Db).CreateJobHandlers().Single(h => h.Kind == JobKind.Render);
|
||||
Assert.False(client is ISelectiveJobHandler, "a client renders whatever it is given");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerTakesMp4JobsOnceNoRenderNodeCanAndOnlyThen()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic" };
|
||||
var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = ProcessingJobs.Render(sequence, Hevc, 96, 64).ParametersJson };
|
||||
async Task<bool> AcceptsAsync(Func<Job, Titano.Protocol.RenderJobParameters, CancellationToken, Task<bool>>? awaits)
|
||||
{
|
||||
var server = new ProcessingService(fx.Db, new ProcessingOptions { Host = EncoderHost.Server, AwaitsRenderNode = awaits });
|
||||
return await ((ISelectiveJobHandler)server.CreateJobHandlers().Single(h => h.Kind == JobKind.Render)).AcceptsAsync(job, fx.Ct);
|
||||
}
|
||||
|
||||
Titano.Protocol.RenderJobParameters? asked = null;
|
||||
Assert.True(await AcceptsAsync((_, p, _) => { asked = p; return Task.FromResult(false); }), "no node can take it");
|
||||
Assert.Equal(("hevc", 96, 64), (asked!.Codec, asked.Width, asked.Height));
|
||||
Assert.False(await AcceptsAsync(null), "without a node check, MP4 jobs always wait");
|
||||
Assert.False(await AcceptsAsync((_, _, _) => throw new InvalidOperationException("database unreachable")), "unknown: keeps waiting");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerRendersAsMjpegWhatNoRenderNodeTookAndSaysSo()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context, o => o with { Host = EncoderHost.Server, AwaitsRenderNode = (_, _, _) => Task.FromResult(false) });
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var request = ProcessingJobs.Render(sequence, Hevc, 96, 64);
|
||||
var job = await fx.WaitForAsync((await fx.EnqueueAsync(request)).Id, JobState.Done);
|
||||
|
||||
var avi = await File.ReadAllBytesAsync(Path.Combine(fx.Folder(sequence).Exports, "clip-MJPEG.avi"), fx.Ct);
|
||||
Assert.Equal(("RIFF", "AVI "), (Encoding.ASCII.GetString(avi, 0, 4), Encoding.ASCII.GetString(avi, 8, 4)));
|
||||
var render = (await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct)).Single();
|
||||
var preset = Loc.L("Export.Preset.Custom");
|
||||
Assert.Equal((preset, "Mjpeg", 96, 64), (render.PresetName, render.Codec, render.Width, render.Height));
|
||||
Assert.Contains(Loc.L("Export.Log.NoRenderNode", preset, "HEVC", "MJPEG"), job.LogTail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABatchForAServerBecomesOneJobPerPreset()
|
||||
{
|
||||
@@ -243,6 +283,11 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.True(jobs.All(j => j.Kind == JobKind.Render && j.Targets.SequenceEqual([sequence.Id])), "render jobs of the sequence");
|
||||
Assert.True(parameters.All(p => ProcessingJobs.ReadExport(p.PresetJson).Batch.Count == 0), "no job carries a batch");
|
||||
Assert.Equal((3840, 2160), (parameters[2].Width, parameters[2].Height));
|
||||
|
||||
// A posted batch written by hand may hold blank entries: they name no preset.
|
||||
var posted = System.Text.Json.JsonSerializer.Deserialize(WithPreset("""{"preset":{"isAuto":false,"manual":"mjpeg-avi"},"batch":[null," ","gif-preview"]}"""),
|
||||
Titano.Protocol.ProtocolJson.Default.RenderJobParameters)!;
|
||||
Assert.SequenceEqual(["mjpeg", "gif"], ProcessingJobs.Split(posted, 96, 64).Select(p => p.Codec));
|
||||
}
|
||||
|
||||
/// <summary>MJPEG job parameters whose preset JSON is <paramref name="presetJson"/>.</summary>
|
||||
|
||||
Reference in new issue
Block a user