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
90 lines
4.3 KiB
C#
90 lines
4.3 KiB
C#
using Titano.Core.Analysis.Deep;
|
||
using Titano.Core.Export;
|
||
using Titano.Core.Imaging;
|
||
using Titano.Core.Model;
|
||
using Titano.Core.Render;
|
||
using Titano.Core.Video;
|
||
using Titano.Core.Video.Managed;
|
||
using Titano.Data.Archiving;
|
||
using Titano.Protocol;
|
||
|
||
namespace Titano.Data.Processing;
|
||
|
||
/// <summary>
|
||
/// What differs between the hosts that analyse and render (BRIEF §4.2): decoders (inside <see cref="Archive"/>),
|
||
/// encoders and where the work runs. Client: WIC then managed decoders, Media Foundation then managed encoders;
|
||
/// server: managed only.
|
||
/// </summary>
|
||
public sealed record ProcessingOptions
|
||
{
|
||
/// <summary><see cref="SequenceChanged"/> after a render was recorded.</summary>
|
||
public const string RenderedChange = "renders";
|
||
|
||
/// <summary><see cref="SequenceChanged"/> after the advisor changed the project.</summary>
|
||
public const string SettingsChange = "settings";
|
||
|
||
/// <summary>Decoders, lease owner and lease timing for the sidecar and project writes.</summary>
|
||
public ArchiveServiceOptions Archive { get; init; } = new();
|
||
|
||
/// <summary>Encoder providers in priority order.</summary>
|
||
public IReadOnlyList<IVideoEncoderProvider> Encoders { get; init; } = [new ManagedEncoderProvider()];
|
||
|
||
/// <summary>
|
||
/// Whether a render of the given preset (its base preset id) may use hardware encoders (Settings › Rendering); when
|
||
/// not, it gets only the software ones. Asked at every render, so a changed preference applies to the next one.
|
||
/// </summary>
|
||
public Func<string, bool> AllowsHardware { get; init; } = _ => true;
|
||
|
||
/// <summary>
|
||
/// Told after a job changed a sequence: <see cref="RenderedChange"/> (a render was recorded) or
|
||
/// <see cref="SettingsChange"/> (the advisor changed Auto values). A server tells its connected clients (BRIEF §14.3).
|
||
/// A failure is logged and never fails the job.
|
||
/// </summary>
|
||
public Func<Guid, string, CancellationToken, Task>? SequenceChanged { get; init; }
|
||
|
||
/// <summary>The server delegates platform codecs to render nodes (<see cref="AwaitsRenderNode"/>).</summary>
|
||
public EncoderHost Host { get; init; } = EncoderHost.Client;
|
||
|
||
/// <summary>
|
||
/// Server: whether a queued render job that needs a platform encoder still waits for a render node (BRIEF §14.7). Once
|
||
/// it does not, the server renders it itself, every output only a node could make as MJPEG in AVI at the same size and
|
||
/// frame rate, and says so in the job log. Null: such jobs always wait for a node.
|
||
/// </summary>
|
||
public Func<Job, RenderJobParameters, CancellationToken, Task<bool>>? AwaitsRenderNode { get; init; }
|
||
|
||
/// <summary>Recorded with every render this host produces (client or server name).</summary>
|
||
public string ProducedBy { get; init; } = Environment.MachineName;
|
||
|
||
public DeepAnalysisOptions DeepAnalysis { get; init; } = DeepAnalysisOptions.Default;
|
||
|
||
/// <summary>Read-ahead and memory budget of the render decode window.</summary>
|
||
public FrameWindowOptions FrameWindow { get; init; } = new();
|
||
|
||
public RenderOptions Render { get; init; } = RenderOptions.Default;
|
||
|
||
/// <summary>Tells <see cref="SequenceChanged"/>; a failure is logged, never passed on to the job.</summary>
|
||
internal async Task NotifyAsync(Guid sequenceId, string change, CancellationToken cancellationToken)
|
||
{
|
||
if (SequenceChanged is null) return;
|
||
try
|
||
{
|
||
await SequenceChanged(sequenceId, change, cancellationToken).ConfigureAwait(false);
|
||
}
|
||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||
{
|
||
Core.Diagnostics.Log.Warning("processing", $"The {change} change of sequence {sequenceId} could not be announced", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary><see cref="Encoders"/> without their hardware encoders, for renders <see cref="AllowsHardware"/> keeps off them.</summary>
|
||
internal IReadOnlyList<IVideoEncoderProvider> SoftwareEncoders =>
|
||
[.. Encoders.Select(e => e.Capabilities.Any(c => c.Hardware) ? new SoftwareEncoderProvider(e) : e)];
|
||
|
||
/// <summary>
|
||
/// Encoders the advisor may count on: this machine's on a client; none listed on the server (render nodes can
|
||
/// produce any codec, so the advisor rules none out).
|
||
/// </summary>
|
||
internal IReadOnlyList<EncoderCapability> AdvisorCodecs =>
|
||
Host == EncoderHost.Server ? [] : [.. Encoders.SelectMany(e => e.Capabilities)];
|
||
}
|