Merge branch 'or1p4-p5' into or1-p4
This commit is contained in:
commit
a433b55be3
27 files changed
+663
-47
No files matched your search
@@ -244,6 +244,55 @@ public sealed class ServerHomeTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerThatReadsAnOlderFormatIsNotSentSettingsItCannotRead()
|
||||
{
|
||||
Assert.Null(ServerJobs.NeedsNewerServer(ProjectSettings.BaseVersion, ProjectSettings.BaseVersion));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), ServerJobs.NeedsNewerServer(2, ProjectSettings.BaseVersion));
|
||||
// A server that says no format reads the base one; a session-less home too.
|
||||
Assert.Equal(ProjectSettings.BaseVersion, Chronos.App.Server.SyncHost.SettingsFormatOf(new ServerInfo("Studio NAS", "1.3.0", 1, [], null, [], new ServerLimits(0, 0))));
|
||||
Assert.Equal(ProjectSettings.BaseVersion, Chronos.App.Server.SyncHost.SettingsFormatOf(null));
|
||||
Assert.Equal(ProjectSettings.CurrentVersion, Chronos.App.Server.SyncHost.SettingsFormatOf(
|
||||
new ServerInfo("Studio NAS", "1.4.0", 1, [], null, [], new ServerLimits(0, 0), SettingsFormat: ProjectSettings.CurrentVersion)));
|
||||
|
||||
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
|
||||
var host = bed.Host(new AppSettings { WorkspaceAutoSync = false, WorkspaceVersionOnRender = false });
|
||||
var server = new FakeServer(bed) { SettingsFormat = ProjectSettings.BaseVersion };
|
||||
Connect(host, server);
|
||||
var projectId = await CheckoutAsync(bed, host);
|
||||
var source = new WorkspaceSequenceSource(host.Sync, projectId, bed.Db, DecoderFactory.CreateClient(null), bed.Engine,
|
||||
new WorkspaceServerHome(() => null, () => null));
|
||||
var content = await source.LoadAsync(bed.Ct);
|
||||
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
||||
var ui = new RecordingUi();
|
||||
await using (session)
|
||||
using (var menu = new ProjectMenuViewModel(host, source, session, ui))
|
||||
{
|
||||
await menu.RefreshAsync();
|
||||
// A change of the base format goes to the older server as before.
|
||||
Assert.True(session.SetHero(2));
|
||||
Assert.Null(menu.PushBlockedReason);
|
||||
Assert.True(menu.SyncCommand.CanExecute(null));
|
||||
|
||||
// A turn needs format 2: Sync is disabled saying why, and a render of it is held.
|
||||
Assert.True(session.Edit(p => p with { Camera = p.Camera with { Rotate = 90 } }));
|
||||
Assert.True(await session.FlushAsync());
|
||||
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), menu.PushBlockedReason);
|
||||
Assert.Equal(menu.PushBlockedReason, menu.SyncToolTip);
|
||||
Assert.False(menu.SyncCommand.CanExecute(null));
|
||||
Assert.False(await menu.ReadyToRenderAsync(), "the server cannot read it");
|
||||
Assert.Equal((Loc.L("Editor.Workspace.RenderHeld"), true), (ui.Toasts[^1].Title, ui.Toasts[^1].IsError));
|
||||
var before = host.Store.Find(projectId)!.ReadBundle().Workspace!.Base!.VersionId;
|
||||
await menu.SyncAsync();
|
||||
Assert.Equal(before, host.Store.Find(projectId)!.ReadBundle().Workspace!.Base!.VersionId, "nothing was sent");
|
||||
|
||||
// A server of this format takes it.
|
||||
server.SettingsFormat = ProjectSettings.CurrentVersion;
|
||||
Assert.Null(menu.PushBlockedReason);
|
||||
Assert.True(menu.SyncCommand.CanExecute(null));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The home a workspace project of the test sequence names on <see cref="Server"/>.</summary>
|
||||
private static BundleHome ServerHome(WorkspaceTestBed bed) => new(BundleHome.ServerKind, bed.SequenceId, null, Server);
|
||||
|
||||
@@ -276,6 +325,9 @@ public sealed class ServerHomeTests(TestContext context)
|
||||
|
||||
public HashSet<Guid> Deleted { get; } = [];
|
||||
|
||||
/// <summary>The settings format the server reads, as its info says.</summary>
|
||||
public int SettingsFormat { get; set; } = ProjectSettings.CurrentVersion;
|
||||
|
||||
public async Task<HomeSequence> SequenceAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var sequence = await Reach(() => Inner.SequenceAsync(cancellationToken));
|
||||
|
||||
@@ -128,6 +128,22 @@ public sealed class EncoderSelectorTests
|
||||
Assert.Equal((1080, 606), (odd.Settings.Width, odd.Settings.Height));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APortraitFrameReadsTheLimitTurned()
|
||||
{
|
||||
// An encoder announced as 4096×2304 takes 4K at 9:16: its limit is long edge × short edge.
|
||||
var portrait = EncoderSelector.Select(Request(VideoCodec.H264, 2160, 3840), Client(SoftwareH264), EncoderHost.Client);
|
||||
Assert.Equal((2160, 3840), (portrait.Settings.Width, portrait.Settings.Height));
|
||||
Assert.False(portrait.Notices.Any(n => n.Key is EncoderNotices.ResolutionCappedByEncoder or EncoderNotices.ResolutionCappedByLevel), "not capped");
|
||||
|
||||
var capped = EncoderSelector.Select(Request(VideoCodec.H264, 4320, 7680), Client(SoftwareH264), EncoderHost.Client);
|
||||
Assert.Equal((2304, 4096), (capped.Settings.Width, capped.Settings.Height));
|
||||
Assert.True(capped.Notices.Any(n => n.Key == EncoderNotices.ResolutionCappedByEncoder));
|
||||
|
||||
Assert.True(EncoderSelector.Takes(SoftwareH264, 2304, 4096));
|
||||
Assert.False(EncoderSelector.Takes(SoftwareH264, 2400, 3840), "the short edge is over the limit");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BitRateIsCappedByTheHighestLevel()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Video;
|
||||
|
||||
@@ -26,7 +27,7 @@ internal sealed class CapturingEncoderProvider(string name, params EncoderCapabi
|
||||
public (int Frame, Exception Error)? FailAt { get; set; }
|
||||
|
||||
public bool CanEncode(EncodeSettings settings) => capabilities.Any(c =>
|
||||
c.Codec == settings.Codec && settings.Width <= c.MaxWidth && settings.Height <= c.MaxHeight && (settings.BitDepth == 8 || c.SupportsTenBit));
|
||||
c.Codec == settings.Codec && EncoderSelector.Takes(c, settings.Width, settings.Height) && (settings.BitDepth == 8 || c.SupportsTenBit));
|
||||
|
||||
public IVideoEncoderSession Open(EncodeSettings settings)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Core.Windows.MediaFoundation;
|
||||
@@ -143,6 +144,61 @@ public sealed class MediaFoundationEncoderTests(TestContext context)
|
||||
Assert.Equal(60, report.FrameCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 1, phase 4: 4K at 9:16 is 2160×3840. Each H.264 encoder of this machine is asked for portrait UHD and
|
||||
/// its landscape twin: none takes one and refuses the other, so the announced limits are a long edge × short edge
|
||||
/// (<see cref="EncoderSelector.Takes"/>), and portrait UHD is announced wherever landscape UHD is. Encoders that refuse
|
||||
/// both (Microsoft's DX12 encoder on some GPUs) are left to the provider, which then opens the next one.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
[Timeout(180_000)]
|
||||
public void PortraitUhdH264EncodesWhereLandscapeDoes()
|
||||
{
|
||||
RequireMediaFoundation();
|
||||
var provider = new MediaFoundationEncoderProvider();
|
||||
var h264 = provider.Capabilities.Where(c => c.Codec == VideoCodec.H264).ToList();
|
||||
if (h264.Count == 0) TestContext.Skip("No H.264 encoder on this machine");
|
||||
foreach (var capability in h264)
|
||||
{
|
||||
var (portrait, landscape) = (Accepts(capability, 2160, 3840), Accepts(capability, 3840, 2160));
|
||||
Assert.Equal(landscape, portrait, $"{capability.Name} takes portrait UHD as it takes landscape UHD");
|
||||
Assert.Equal(EncoderSelector.Takes(capability, 3840, 2160), EncoderSelector.Takes(capability, 2160, 3840), "announced either way round");
|
||||
}
|
||||
var request = Settings(Path.Combine(context.CreateTempDirectory(), "portrait.mp4"), VideoCodec.H264, 8);
|
||||
Assert.Equal(provider.CanEncode(request with { Width = 3840, Height = 2160 }), provider.CanEncode(request with { Width = 2160, Height = 3840 }));
|
||||
|
||||
bool Accepts(EncoderCapability capability, int width, int height)
|
||||
{
|
||||
var settings = Settings(Path.Combine(context.CreateTempDirectory(), $"{width}x{height}.mp4"), VideoCodec.H264, 8) with
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
EncoderName = capability.Name,
|
||||
PreferHardware = capability.Hardware,
|
||||
BitRate = 20_000_000,
|
||||
};
|
||||
try
|
||||
{
|
||||
using (var session = provider.Open(settings))
|
||||
{
|
||||
using var frame = new ImageBuffer(width, height);
|
||||
for (var c = 0; c < 3; c++) frame.Plane(c).Fill(0.25f);
|
||||
for (var f = 0; f < 3; f++) session.WriteFrame(frame, Frame30);
|
||||
session.Complete();
|
||||
}
|
||||
var report = Mp4Inspector.Inspect(settings.OutputPath);
|
||||
context.Log($"{capability.Name} {width}×{height}: {report}");
|
||||
return report.IsValid && (report.Width, report.Height) == (width, height);
|
||||
}
|
||||
catch (NotSupportedException ex)
|
||||
{
|
||||
context.Log($"{capability.Name} {width}×{height}: refused ({ex.InnerException?.Message ?? ex.Message})");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
[Timeout(60_000)]
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using Chronos.Core.Diagnostics.Synthetic;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Processing;
|
||||
|
||||
/// <summary>
|
||||
/// The project of a sequence as the engine reads and writes it (owner review 1, phase 4): a format-1 project stays format 1
|
||||
/// through every edit that uses nothing newer, a transform raises it to 2 and its removal brings it back, and settings of
|
||||
/// a newer Chronos are refused saying so in the user's language.
|
||||
/// </summary>
|
||||
[Category("processing")]
|
||||
public sealed class ProjectStoreTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task AnEditNeverRaisesTheFormatOfAProjectThatUsesNothingNewer()
|
||||
{
|
||||
await using var fixture = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fixture.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { Width = 64, Height = 48, FrameCount = 4 }));
|
||||
var store = new ProjectStore(fixture.Db, new SequenceWriter(new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) }));
|
||||
async Task<int> StoredFormatAsync()
|
||||
{
|
||||
var row = (await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!;
|
||||
var file = await File.ReadAllTextAsync(fixture.Folder(sequence).ProjectPath, fixture.Ct);
|
||||
Assert.Equal(row.SettingsJson, file, "the index and project.json hold the same text");
|
||||
return ProjectContent.FormatOf(file);
|
||||
}
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } }, fixture.Ct));
|
||||
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
|
||||
// A read project of the base format is never stamped higher, even when it says the highest this Chronos reads.
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Version = ProjectSettings.CurrentVersion, HeroFrame = 2 }, fixture.Ct));
|
||||
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Camera = p.Camera with { Rotate = 90 } }, fixture.Ct));
|
||||
Assert.Equal(2, await StoredFormatAsync());
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Camera = p.Camera with { Rotate = 0 } }, fixture.Ct));
|
||||
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
|
||||
Assert.False(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Version = ProjectSettings.BaseVersion }, fixture.Ct), "nothing changed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsOfANewerChronosAreRefusedSayingSo()
|
||||
{
|
||||
var refused = Assert.Throws<InvalidDataException>(() => ProjectStore.Parse("""{"version":3,"camera":{"rotate":90}}"""));
|
||||
Assert.Equal(Loc.L("Errors.Render.NewerSettings"), refused.Message);
|
||||
Assert.Equal(90, ProjectStore.Parse("""{"version":2,"camera":{"rotate":90}}""").Camera.Rotate);
|
||||
// Text that is not a project keeps its own reason.
|
||||
Assert.NotEqual(Loc.L("Errors.Render.NewerSettings"), Assert.Throws<InvalidDataException>(() => ProjectStore.Parse("[1]")).Message);
|
||||
}
|
||||
}
|
||||
@@ -599,6 +599,65 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.SequenceEqual(["mjpeg", "gif"], ProcessingJobs.Split(posted, 96, 64).Select(p => p.Codec));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 1, phase 4: a render job carries the output size its settings give it (the chosen proportions win over a
|
||||
/// fixed-size preset, a quarter turn swaps a source-sized output) and the settings format its render needs, so a render
|
||||
/// node is matched to what it will write; a job posted by an older client gets both from the server (<see cref="ProcessingJobs.Split"/>).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void RenderJobsCarryTheSizeAndFormatOfTheirSettings()
|
||||
{
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic", Title = "Roof" };
|
||||
var uhd = new ExportSettings { Preset = new Auto<string>().WithManual("4k-h264") };
|
||||
var portrait = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16") } };
|
||||
static Chronos.Protocol.RenderJobParameters Read(Chronos.Data.Archiving.Jobs.ArchiveJobRequest request) => ProcessingJobs.ReadRender(request.ParametersJson).Parameters;
|
||||
|
||||
var adapted = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, portrait));
|
||||
Assert.Equal((2160, 3840, 2), (adapted.Width, adapted.Height, adapted.RequiredSettingsFormat));
|
||||
var source = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, new ProjectSettings()));
|
||||
Assert.Equal((3840, 2160, 1), (source.Width, source.Height, source.RequiredSettingsFormat));
|
||||
// A source-sized output turns with the picture; the turn needs format 2.
|
||||
var png = new ExportSettings { Preset = new Auto<string>().WithManual("png-sequence") };
|
||||
var turned = Read(ProcessingJobs.Render(sequence, png, 6000, 4000, new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }));
|
||||
Assert.Equal((4000, 6000, 2), (turned.Width, turned.Height, turned.RequiredSettingsFormat));
|
||||
// The sequence's own settings when the job embeds none.
|
||||
var own = Read(ProcessingJobs.Render(sequence with { SettingsJson = portrait.ToJson() }, uhd, 6000, 4000));
|
||||
Assert.Equal((2160, 3840, 2), (own.Width, own.Height, own.RequiredSettingsFormat));
|
||||
|
||||
// Posted by an older client (the preset's size, no format) with a batch: the server sizes each job for the settings.
|
||||
var posted = Read(ProcessingJobs.Render(sequence, uhd with { Batch = ["1080p-h264"] }, 6000, 4000)) with { SettingsJson = portrait.ToJson() };
|
||||
Assert.Equal((3840, 2160, 1), (posted.Width, posted.Height, posted.RequiredSettingsFormat));
|
||||
var split = ProcessingJobs.Split(posted, 6000, 4000, portrait);
|
||||
Assert.SequenceEqual([(2160, 3840, 2), (1080, 1920, 2)], split.Select(p => (p.Width, p.Height, p.RequiredSettingsFormat)));
|
||||
Assert.Equal(split[0], ProcessingJobs.Routed(split[0], portrait, 6000, 4000), "a size already adapted stays");
|
||||
Assert.Equal((3840, 2160, 1), ProcessingJobs.Split(posted, 6000, 4000).Select(p => (p.Width, p.Height, p.RequiredSettingsFormat)).First(),
|
||||
"settings that cannot be read keep the size the job was posted with");
|
||||
// What the desktop asks of a server before a render: the highest format of the export and its batch.
|
||||
Assert.Equal(1, ProcessingJobs.RequiredFormat(portrait, png, 6000, 4000), "a source-sized output keeps the proportions");
|
||||
Assert.Equal(2, ProcessingJobs.RequiredFormat(portrait, png with { Batch = ["4k-h264"] }, 6000, 4000));
|
||||
}
|
||||
|
||||
/// <summary>Settings of a newer Chronos fail the render with the reason in the user's language, never as an English message.</summary>
|
||||
[Test]
|
||||
public async Task AnOverFormatRenderFailsSayingANewerChronosIsNeeded()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var parameters = ProcessingJobs.ReadRender(ProcessingJobs.Render(sequence, Mjpeg, 96, 64).ParametersJson).Parameters with
|
||||
{
|
||||
SettingsJson = """{"version":3,"camera":{"rotate":90},"grade":{"lut":"teal"}}""",
|
||||
};
|
||||
var request = new Chronos.Data.Archiving.Jobs.ArchiveJobRequest(JobKind.Render, [sequence.Id], "newer",
|
||||
System.Text.Json.JsonSerializer.Serialize(parameters, Chronos.Protocol.ProtocolJson.Default.RenderJobParameters), JobPriority.User);
|
||||
Assert.Equal(3, ProcessingJobs.ReadRender(ProcessingJobs.Render(sequence, Mjpeg, 96, 64,
|
||||
ProjectSettings.FromJson(parameters.SettingsJson, allowNewer: true)).ParametersJson).Parameters.RequiredSettingsFormat, "routed to none older");
|
||||
var failed = await fx.WaitForAsync((await fx.EnqueueAsync(request)).Id, JobState.Failed);
|
||||
Assert.Equal(Loc.L("Errors.Render.NewerSettings"), failed.Error);
|
||||
Assert.Empty(await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
/// <summary>MJPEG job parameters whose preset JSON is <paramref name="presetJson"/>.</summary>
|
||||
private static string WithPreset(string presetJson) => System.Text.Json.JsonSerializer.Serialize(
|
||||
new Chronos.Protocol.RenderJobParameters("MJPEG", presetJson, "mjpeg", 96, 64, false, null), Chronos.Protocol.ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
@@ -498,6 +498,42 @@ public sealed class ProjectTests(TestContext context)
|
||||
Assert.Contains(ServerCapabilities.Projects, (await client.GetInfoAsync(context.Cancellation)).Capabilities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 1, phase 4: the server announces the settings format it reads, and takes the versions of the formats it
|
||||
/// reads (1, and 2 with a turn or a look), refusing a newer one with 422 <c>newer_format</c>, nothing stored.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task TheServerTakesTheSettingsFormatsItAnnounces()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
using (var anonymous = new ChronosClient(server.HttpBase, new CertificatePinning([]), "tests"))
|
||||
Assert.Equal(ProjectSettings.CurrentVersion, (await anonymous.GetInfoAsync(context.Cancellation)).SettingsFormat);
|
||||
Assert.Equal(2, ProjectSettings.CurrentVersion);
|
||||
|
||||
var (http, _, token) = await server.UserAsync("alberto", "editor");
|
||||
using var alberto = Client(server, token);
|
||||
var sid = await SequenceAsync(server, token, 2);
|
||||
var main = (await alberto.ListProjectsAsync(sid)).Single(p => p.IsMain);
|
||||
var head = await alberto.GetProjectHeadAsync(sid, main.Id);
|
||||
var home = ProjectWire.ToHomeFrames(await alberto.GetProjectFramesAsync(sid));
|
||||
|
||||
var plain = Version(head, new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.3 } }, home);
|
||||
Assert.Equal(1, plain.SettingsFormat);
|
||||
var v2 = Assert.NotNull((await alberto.PushProjectVersionAsync(sid, main.Id, plain)).Version);
|
||||
var turned = Version(v2, new ProjectSettings { Camera = new CameraSettings { Rotate = 90, Mirror = true }, Look = new LookSettings { Filter = "sepia" } }, home);
|
||||
Assert.Equal(2, turned.SettingsFormat);
|
||||
var v3 = Assert.NotNull((await alberto.PushProjectVersionAsync(sid, main.Id, turned)).Version);
|
||||
Assert.Equal(2, ProjectContent.FormatOf(v3.SettingsJson));
|
||||
var mirrored = ProjectSettings.FromJson(Assert.NotNull((await server.Database.Sequences.GetAsync(sid))!.SettingsJson));
|
||||
Assert.Equal((90, true, "sepia"), (mirrored.Camera.Rotate, mirrored.Camera.Mirror, mirrored.Look?.Filter), "Main's head is the sequence's settings");
|
||||
|
||||
const string future = """{"version":3,"camera":{"rotate":90}}""";
|
||||
var newer = Version(v3, new ProjectSettings(), home) with { SettingsJson = future, ContentHash = ProjectContent.Hash(future), SettingsFormat = 3 };
|
||||
using (var raw = await http.PostAsJsonAsync($"/api/v1/sequences/{sid}/projects/{main.Id}/versions", newer, ProtocolJson.Default.ProjectVersionDto))
|
||||
await raw.ExpectErrorAsync(HttpStatusCode.UnprocessableEntity, ProjectErrors.NewerFormat);
|
||||
Assert.Equal(3, (await alberto.GetProjectAsync(sid, main.Id)).HeadNumber);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheFramesOfAHomeAreOfOneFramesVersionWithTheAliasesOfItsConversions()
|
||||
{
|
||||
|
||||
@@ -132,6 +132,9 @@ public sealed class RenderNodeClientTests(TestContext context)
|
||||
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");
|
||||
// And the settings format it renders (owner review 1, phase 4), so the server gives it only jobs it renders as asked.
|
||||
var stored = Assert.NotNull(Chronos.Server.Api.Dto.Capabilities(Assert.NotNull(await server.Database.RenderNodes.GetAsync(id))));
|
||||
Assert.Equal(ProjectSettings.CurrentVersion, stored.SettingsFormat);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -3,10 +3,14 @@ using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Server.Api;
|
||||
using Chronos.Server.Jobs;
|
||||
using Chronos.Server.Storage;
|
||||
using Chronos.Testing;
|
||||
@@ -94,6 +98,96 @@ public sealed class RenderNodeTests(TestContext context)
|
||||
Assert.Equal(uhd.Id, (await claim.ReadAsync(ProtocolJson.Default.ClaimedJob)).Job.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 1, phase 4: a node that does not announce its settings format (an older Chronos) reads format 1, and is
|
||||
/// never given a job it would render otherwise than asked: settings of format 2 (a turn), the chosen proportions in a
|
||||
/// fixed-size preset (4K at 9:16 = 2160×3840), or a sequence's settings changed to format 2 after the job was queued. A
|
||||
/// node of format 2 takes them, a portrait UHD frame on an encoder announced as 4096×2304 included.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnlyNodesThatReadTheSettingsFormatTakeTheJobsThatNeedIt()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
using var old = await editor.PostAsync("/api/v1/nodes/register", new StringContent(
|
||||
"""{"clientName":"old-pc","encoders":[{"codec":"h264","name":"H.264 Encoder MFT","hardware":false,"tenBit":false}],"maxWidth":4096,"maxHeight":4096}""",
|
||||
System.Text.Encoding.UTF8, "application/json"));
|
||||
var older = await old.ReadAsync(ProtocolJson.Default.RenderNodeDto);
|
||||
var stored = Assert.NotNull(Dto.Capabilities(Assert.NotNull(await server.Database.RenderNodes.GetAsync(older.Id))));
|
||||
Assert.Equal(1, stored.SettingsFormat);
|
||||
|
||||
var sequence = await JobApiTests.CreateSequenceAsync(editor);
|
||||
var turned = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }.ToJson();
|
||||
var portrait = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16") } }.ToJson();
|
||||
var v2 = await JobApiTests.CreateAsync(editor, "render", sequence, WithSettings(H264Job(3840, 2160), turned));
|
||||
var proportions = await JobApiTests.CreateAsync(editor, "render", sequence, WithSettings(H264Job(3840, 2160), portrait));
|
||||
var routed = ProcessingJobs.ReadRender((await server.Database.Jobs.GetAsync(proportions.Id))!.ParametersJson).Parameters;
|
||||
Assert.Equal((2160, 3840, 2), (routed.Width, routed.Height, routed.RequiredSettingsFormat), "the server sized the job posted at the preset's size");
|
||||
// Queued as format 1, then the sequence's own settings took a turn.
|
||||
var plain = await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(3840, 2160));
|
||||
Assert.Equal(1, ProcessingJobs.ReadRender((await server.Database.Jobs.GetAsync(plain.Id))!.ParametersJson).Parameters.RequiredSettingsFormat);
|
||||
var row = (await server.Database.Sequences.GetAsync(sequence))!;
|
||||
await server.Database.Sequences.EditAsync(sequence, new SequenceEdit { SettingsJson = turned }, row.SettingsVersion);
|
||||
using (var none = await editor.PostAsync($"/api/v1/nodes/{older.Id}/claim", null)) await none.ExpectAsync(HttpStatusCode.NoContent);
|
||||
|
||||
// The software H.264 encoder takes portrait UHD as a long edge × short edge, on a node that knows it.
|
||||
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)], 4096, 2304, SettingsFormat: 2), ProtocolJson.Default.RegisterNodeRequest);
|
||||
var newer = await registered.ReadAsync(ProtocolJson.Default.RenderNodeDto);
|
||||
var claimed = new List<Guid>();
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
using var claim = await editor.PostAsync($"/api/v1/nodes/{newer.Id}/claim", null);
|
||||
claimed.Add((await claim.ReadAsync(ProtocolJson.Default.ClaimedJob)).Job.Id);
|
||||
}
|
||||
Assert.SequenceEqual(new[] { v2.Id, proportions.Id, plain.Id }.Order(), claimed.Order());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encoder's limit is a long edge × short edge on a node of format 2 (its encoders take portrait UHD within 4096×2304);
|
||||
/// an older node shrinks a frame to the limit as announced, so it is held to that.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void APortraitFrameFitsALandscapeLimitOnlyOnANodeThatKnowsIt()
|
||||
{
|
||||
var job = new RenderJobParameters("4K", "{}", "h264", 2160, 3840, UseProxies: false, null, RequiredSettingsFormat: 2);
|
||||
NodeEncoder[] software = [new("h264", "H.264 Encoder MFT", false, false, 4096, 2304)];
|
||||
var older = new RegisterNodeRequest("old-pc", software, 4096, 2304);
|
||||
var newer = older with { ClientName = "studio-pc", SettingsFormat = 2 };
|
||||
Assert.False(RenderNodeService.CanEncode(older, job));
|
||||
Assert.True(RenderNodeService.CanEncode(newer, job));
|
||||
Assert.True(RenderNodeService.Renders(newer, job));
|
||||
Assert.False(RenderNodeService.Renders(older, job with { Width = 1080, Height = 1920 }), "format 2 is never sent to a format-1 node");
|
||||
Assert.True(RenderNodeService.Renders(older, job with { Width = 3840, Height = 2160, RequiredSettingsFormat = 1 }));
|
||||
Assert.False(RenderNodeService.CanEncode(newer, job with { Width = 2400 }), "both edges above the short limit");
|
||||
}
|
||||
|
||||
/// <summary>A job waits for a node only while one online could render it: one of an older settings format cannot.</summary>
|
||||
[Test]
|
||||
public async Task AJobDoesNotWaitForNodesThatCannotReadItsSettings()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, o => o.NodeTimeoutSeconds = 60);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
await RegisterAsync(editor, "old-pc", "h264", 4096);
|
||||
var sequence = await JobApiTests.CreateSequenceAsync(editor);
|
||||
var turned = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }.ToJson();
|
||||
var created = await JobApiTests.CreateAsync(editor, "render", sequence, WithSettings(H264Job(1920, 1080), turned));
|
||||
var queued = (await server.Database.Jobs.GetAsync(created.Id))!;
|
||||
var parameters = ProcessingJobs.ReadRender(queued.ParametersJson).Parameters;
|
||||
Assert.Equal(2, parameters.RequiredSettingsFormat);
|
||||
// Waited longer than a node may stay silent: only an online node that renders it keeps it waiting.
|
||||
var job = queued with { Created = DateTimeOffset.UtcNow - TimeSpan.FromSeconds(61) };
|
||||
RenderNodeAvailability Availability() => new(server.Database, server.Options, TimeProvider.System);
|
||||
|
||||
Assert.True(await Availability().AwaitsNodeAsync(queued with { Created = DateTimeOffset.UtcNow }, parameters, context.Cancellation), "a node may be reconnecting");
|
||||
Assert.False(await Availability().AwaitsNodeAsync(job, parameters, context.Cancellation), "only a node of format 1 is online");
|
||||
Assert.True(await Availability().AwaitsNodeAsync(job, parameters with { RequiredSettingsFormat = 1 }, context.Cancellation), "it renders a job of format 1");
|
||||
using (var registered = await editor.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("studio-pc", [new NodeEncoder("h264", "NVENC", true, false)],
|
||||
4096, 4096, SettingsFormat: 2), ProtocolJson.Default.RegisterNodeRequest))
|
||||
await registered.ExpectAsync(HttpStatusCode.OK);
|
||||
Assert.True(await Availability().AwaitsNodeAsync(job, parameters, context.Cancellation), "a node of format 2 is online");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheOutputUploadBecomesARenderAndFinishesTheJob()
|
||||
{
|
||||
@@ -244,6 +338,10 @@ public sealed class RenderNodeTests(TestContext context)
|
||||
new RenderJobParameters("H.264", """{"preset":{"isAuto":false,"manual":"4k-h264"}}""", "h264", width, height, UseProxies: false, null),
|
||||
ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
/// <summary>Render job parameters <paramref name="parametersJson"/> with <paramref name="settingsJson"/> embedded.</summary>
|
||||
private static string WithSettings(string parametersJson, string settingsJson) => JsonSerializer.Serialize(
|
||||
JsonSerializer.Deserialize(parametersJson, ProtocolJson.Default.RenderJobParameters)! with { SettingsJson = settingsJson }, ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
internal static async Task<RenderNodeDto> RegisterAsync(HttpClient client, string name, string codec, int maxWidth)
|
||||
{
|
||||
using var response = await client.PostAsJsonAsync("/api/v1/nodes/register",
|
||||
|
||||
Reference in new issue
Block a user