Owner review 1, phase 4 (P5). A render job now carries the output size its settings give (RenderSize, proportions win) and the settings format it needs, resolved on the server before the job is split, so only nodes that read that format and whose encoder takes the frame claim it, and a job no online node can read no longer waits for one. Nodes and the server announce the format they read; settings of a newer Chronos fail saying so. Encoder size limits are read as long edge x short edge: Media Foundation's software H.264 encoder, announced as 4096x2304, accepts portrait 2160x3840 (probed on this PC), so EncoderSelector and the provider take either orientation and cap a portrait frame against the turned limit. On the desktop, Sync and Send-and-render are disabled with the NeedsNewerServer tooltip while the server reads an older format than the working settings need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.3 KiB
C#
59 lines
2.3 KiB
C#
using Chronos.Core.Export;
|
|
using Chronos.Core.Imaging;
|
|
using Chronos.Core.Video;
|
|
|
|
namespace Chronos.Core.Tests.Render;
|
|
|
|
/// <summary>One encode recorded by <see cref="CapturingEncoderProvider"/>.</summary>
|
|
internal sealed class CapturedEncode(EncodeSettings settings)
|
|
{
|
|
public EncodeSettings Settings { get; } = settings;
|
|
public List<ImageBuffer> Frames { get; } = [];
|
|
public List<long> Durations { get; } = [];
|
|
public bool Completed { get; set; }
|
|
public bool Disposed { get; set; }
|
|
}
|
|
|
|
/// <summary>Test encoder: keeps a copy of every frame, can pretend to be hardware or to fail at a given frame.</summary>
|
|
internal sealed class CapturingEncoderProvider(string name, params EncoderCapability[] capabilities) : IVideoEncoderProvider
|
|
{
|
|
public string Name => name;
|
|
|
|
public IReadOnlyList<EncoderCapability> Capabilities => capabilities;
|
|
|
|
public List<CapturedEncode> Encodes { get; } = [];
|
|
|
|
/// <summary>When set, WriteFrame throws this for the frame with that zero-based index.</summary>
|
|
public (int Frame, Exception Error)? FailAt { get; set; }
|
|
|
|
public bool CanEncode(EncodeSettings settings) => capabilities.Any(c =>
|
|
c.Codec == settings.Codec && EncoderSelector.Takes(c, settings.Width, settings.Height) && (settings.BitDepth == 8 || c.SupportsTenBit));
|
|
|
|
public IVideoEncoderSession Open(EncodeSettings settings)
|
|
{
|
|
var encode = new CapturedEncode(settings);
|
|
Encodes.Add(encode);
|
|
var capability = capabilities.First(c => c.Codec == settings.Codec);
|
|
return new Session(this, encode, capability);
|
|
}
|
|
|
|
private sealed class Session(CapturingEncoderProvider owner, CapturedEncode encode, EncoderCapability capability) : IVideoEncoderSession
|
|
{
|
|
public string EncoderName => capability.Name;
|
|
|
|
public bool IsHardware => capability.Hardware;
|
|
|
|
public void WriteFrame(ImageBuffer frame, long duration90k)
|
|
{
|
|
if (owner.FailAt is { } fail && fail.Frame == encode.Frames.Count) throw fail.Error;
|
|
if (frame.Width != encode.Settings.Width || frame.Height != encode.Settings.Height) throw new ArgumentException("size");
|
|
encode.Frames.Add(frame.Clone());
|
|
encode.Durations.Add(duration90k);
|
|
}
|
|
|
|
public void Complete() => encode.Completed = true;
|
|
|
|
public void Dispose() => encode.Disposed = true;
|
|
}
|
|
}
|