diff --git a/src/Titano.Data/Processing/ProcessingJobs.cs b/src/Titano.Data/Processing/ProcessingJobs.cs index 2cb5a8a0..bc990d70 100644 --- a/src/Titano.Data/Processing/ProcessingJobs.cs +++ b/src/Titano.Data/Processing/ProcessingJobs.cs @@ -76,11 +76,12 @@ public static class ProcessingJobs ]; } - /// The batch presets of an export besides its own, each once. + /// The batch presets of an export besides its own, each once (blank entries of a hand-written batch are skipped). internal static IEnumerable BatchPresets(ExportSettings export) { var main = ExportResolver.Resolve(export).BasePresetId; - return export.Batch.Distinct(StringComparer.OrdinalIgnoreCase).Where(id => !id.Equals(main, StringComparison.OrdinalIgnoreCase)); + return export.Batch.Where(id => !string.IsNullOrWhiteSpace(id)).Distinct(StringComparer.OrdinalIgnoreCase) + .Where(id => !id.Equals(main, StringComparison.OrdinalIgnoreCase)); } /// A batch preset rendered with its own values, named and placed like the export it belongs to. diff --git a/src/Titano.Data/Processing/RenderNodeClient.cs b/src/Titano.Data/Processing/RenderNodeClient.cs index 2a5efbf2..db13ffc1 100644 --- a/src/Titano.Data/Processing/RenderNodeClient.cs +++ b/src/Titano.Data/Processing/RenderNodeClient.cs @@ -73,15 +73,15 @@ public sealed class RenderNodeClient : IAsyncDisposable } /// - /// The encoders this node offers: every single-file capability of the host's providers, hardware ones only when the - /// user lets renders use them (). + /// The encoders this node offers, each with its largest output: every single-file capability of the host's + /// providers, hardware ones only when the user lets renders use them (). /// public IReadOnlyList Encoders => [ .. _processing.Encoders.SelectMany(p => p.Capabilities) .Where(c => VideoCodecInfo.DefaultContainer(c.Codec) != ContainerFormat.ImageSequence && (!c.Hardware || _processing.AllowsHardware(ExportResolver.CustomId))) - .Select(c => new NodeEncoder(ProcessingJobs.CodecName(c.Codec), c.Name, c.Hardware, c.SupportsTenBit)), + .Select(c => new NodeEncoder(ProcessingJobs.CodecName(c.Codec), c.Name, c.Hardware, c.SupportsTenBit, c.MaxWidth, c.MaxHeight)), ]; /// Completes when the node has stopped: asked to, or refused by the server (signed out, no render-node right, @@ -107,9 +107,10 @@ public sealed class RenderNodeClient : IAsyncDisposable /// Registers this node (again) and returns its id. public async Task RegisterAsync(CancellationToken cancellationToken) { - var capabilities = _processing.Encoders.SelectMany(p => p.Capabilities).ToList(); - var request = new RegisterNodeRequest(_options.ClientName, Encoders, capabilities.Count > 0 ? capabilities.Max(c => c.MaxWidth) : 0, - capabilities.Count > 0 ? capabilities.Max(c => c.MaxHeight) : 0); + // Each encoder carries its own limit; the node-wide one (for servers that read only that) is the largest offered. + var encoders = Encoders; + var request = new RegisterNodeRequest(_options.ClientName, encoders, encoders.Select(e => e.MaxWidth).DefaultIfEmpty().Max(), + encoders.Select(e => e.MaxHeight).DefaultIfEmpty().Max()); var node = await _client.RegisterNodeAsync(request, cancellationToken).ConfigureAwait(false); _nodeId = node.Id; return node.Id; diff --git a/src/Titano.Protocol/Jobs.cs b/src/Titano.Protocol/Jobs.cs index 6a6d8e5c..38ba16cf 100644 --- a/src/Titano.Protocol/Jobs.cs +++ b/src/Titano.Protocol/Jobs.cs @@ -22,10 +22,17 @@ public sealed record JobDto( /// POST /api/v1/jobs: kind = render, deep-analyse, proxies, thumbs, verify, scan, rebuild, maintenance… public sealed record CreateJobRequest(string Kind, IReadOnlyList Target, string? ParametersJson); -/// POST /api/v1/nodes/register: a client offers its GPU encoders (BRIEF §14.7). +/// +/// POST /api/v1/nodes/register: a client offers its GPU encoders (BRIEF §14.7). × +/// is the largest output of any of them, for encoders that announce no limit of their own. +/// public sealed record RegisterNodeRequest(string ClientName, IReadOnlyList Encoders, int MaxWidth, int MaxHeight); -public sealed record NodeEncoder(string Codec, string Name, bool Hardware, bool TenBit); +/// +/// One encoder of a render node. × is its largest output (0 = not announced: +/// the node's own limit applies), so jobs go only to a node with an encoder of their codec that takes their size. +/// +public sealed record NodeEncoder(string Codec, string Name, bool Hardware, bool TenBit, int MaxWidth = 0, int MaxHeight = 0); public sealed record RenderNodeDto(Guid Id, string ClientName, string Username, IReadOnlyList Encoders, DateTimeOffset LastHeartbeat, string State); diff --git a/src/Titano.Server/Jobs/RenderNodeService.cs b/src/Titano.Server/Jobs/RenderNodeService.cs index f27c4c73..b9f22d6f 100644 --- a/src/Titano.Server/Jobs/RenderNodeService.cs +++ b/src/Titano.Server/Jobs/RenderNodeService.cs @@ -250,11 +250,16 @@ public sealed class RenderNodeService( } } - /// The node has an encoder for the job's codec and handles its resolution (0 = no announced limit). - private static bool CanEncode(RegisterNodeRequest node, RenderJobParameters job) => - node.Encoders.Any(e => string.Equals(e.Codec, job.Codec, StringComparison.OrdinalIgnoreCase)) - && (node.MaxWidth <= 0 || job.Width <= node.MaxWidth) - && (node.MaxHeight <= 0 || job.Height <= node.MaxHeight); + /// + /// The node has an encoder for the job's codec that handles its resolution: the encoder's own limit, else the node's + /// (0 = no announced limit). + /// + internal static bool CanEncode(RegisterNodeRequest node, RenderJobParameters job) => + node.Encoders.Any(e => string.Equals(e.Codec, job.Codec, StringComparison.OrdinalIgnoreCase) + && Fits(job.Width, e.MaxWidth > 0 ? e.MaxWidth : node.MaxWidth) + && Fits(job.Height, e.MaxHeight > 0 ? e.MaxHeight : node.MaxHeight)); + + private static bool Fits(int size, int limit) => limit <= 0 || size <= limit; internal static string? AppendLog(string? tail, string? line) { diff --git a/tests/Titano.Server.Tests/Jobs/RenderNodeClientTests.cs b/tests/Titano.Server.Tests/Jobs/RenderNodeClientTests.cs index ae055ce8..dea231c2 100644 --- a/tests/Titano.Server.Tests/Jobs/RenderNodeClientTests.cs +++ b/tests/Titano.Server.Tests/Jobs/RenderNodeClientTests.cs @@ -87,6 +87,8 @@ public sealed class RenderNodeClientTests(TestContext context) var id = await node.RegisterAsync(context.Cancellation); var registered = (await client.ListNodesAsync(context.Cancellation)).Single(n => n.Id == id); Assert.SequenceEqual(["apng", "gif", "mjpeg"], registered.Encoders.Select(e => e.Codec).Order(StringComparer.Ordinal)); + // Each encoder announces its own largest output, so the server matches job sizes per codec. + Assert.True(registered.Encoders.All(e => (e.MaxWidth, e.MaxHeight) == (65535, 65535)), "per-encoder limits"); } [Test] diff --git a/tests/Titano.Server.Tests/Jobs/RenderNodeTests.cs b/tests/Titano.Server.Tests/Jobs/RenderNodeTests.cs index 0b7610fc..14c52128 100644 --- a/tests/Titano.Server.Tests/Jobs/RenderNodeTests.cs +++ b/tests/Titano.Server.Tests/Jobs/RenderNodeTests.cs @@ -70,6 +70,26 @@ public sealed class RenderNodeTests(TestContext context) } } + [Test] + public async Task EachEncoderTakesOnlyJobsWithinItsOwnSizeLimit() + { + await using var server = await TestServer.StartAsync(context); + var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true); + var sequence = await JobApiTests.CreateSequenceAsync(editor); + // The software H.264 encoder stops at 4096 px although the node's MJPEG encoder writes far larger frames. + using var registered = await editor.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("studio-pc", + [new NodeEncoder("h264", "H.264 Encoder MFT", false, false, 4096, 2304), new NodeEncoder("mjpeg", "Managed MJPEG", false, false, 65535, 65535)], + 65535, 65535), ProtocolJson.Default.RegisterNodeRequest); + var node = await registered.ReadAsync(ProtocolJson.Default.RenderNodeDto); + Assert.Equal((4096, 2304), (node.Encoders[0].MaxWidth, node.Encoders[0].MaxHeight)); + + await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(6144, 3456)); + using (var none = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null)) await none.ExpectAsync(HttpStatusCode.NoContent); + var uhd = await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(3840, 2160)); + using var claim = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null); + Assert.Equal(uhd.Id, (await claim.ReadAsync(ProtocolJson.Default.ClaimedJob)).Job.Id); + } + [Test] public async Task TheOutputUploadBecomesARenderAndFinishesTheJob() { @@ -123,6 +143,10 @@ public sealed class RenderNodeTests(TestContext context) await foreign.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden"); } + private static string H264Job(int width, int height) => JsonSerializer.Serialize( + new RenderJobParameters("H.264", """{"preset":{"isAuto":false,"manual":"4k-h264"}}""", "h264", width, height, UseProxies: false, null), + ProtocolJson.Default.RenderJobParameters); + private static async Task RegisterAsync(HttpClient client, string name, string codec, int maxWidth) { using var response = await client.PostAsJsonAsync("/api/v1/nodes/register",