refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,461 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Chronos.Core.Analysis;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Geometry;
|
||||
using Chronos.Core.Motion;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Video;
|
||||
|
||||
namespace Chronos.Core.Render;
|
||||
|
||||
/// <summary>
|
||||
/// Renders sequences (BRIEF §11). For every planned output frame: source frames come from the
|
||||
/// <see cref="IRenderFrameSource"/> at the working size; per-frame exposure corrections (deflicker, holy grail, white
|
||||
/// balance, regions) are applied; stabilisation, virtual camera and crop are resampled once to the output size;
|
||||
/// fractional positions are synthesised from the bidirectional flow; motion blur follows the flow with shutter-angle
|
||||
/// composition; stacking (median, mean, star trails) and the highlight knee come last, then the encoder. Encoding of a
|
||||
/// frame overlaps the processing of the next. Cancellation and failures leave no output behind (sessions delete their
|
||||
/// partial files on dispose) and every background task is awaited, so exceptions surface exactly once.
|
||||
/// </summary>
|
||||
public sealed class RenderPipeline(IReadOnlyList<IVideoEncoderProvider> encoders, EncoderHost host = EncoderHost.Client)
|
||||
{
|
||||
internal const string LogCategory = "Render";
|
||||
|
||||
/// <summary>Encoder providers in priority order (client: Media Foundation, then managed; server: managed).</summary>
|
||||
public IReadOnlyList<IVideoEncoderProvider> Encoders { get; } = encoders ?? throw new ArgumentNullException(nameof(encoders));
|
||||
|
||||
public EncoderHost Host { get; } = host;
|
||||
|
||||
/// <summary>Geometry, encoder and plan of a target without rendering (Export tab, estimates).</summary>
|
||||
public RenderSetup Setup(RenderInput input, RenderTarget target, RenderOptions? options = null, RenderCorrections? corrections = null) =>
|
||||
RenderSetup.Create(input, target, Encoders, Host, options, corrections);
|
||||
|
||||
/// <summary>Prepares the sequence and renders one target.</summary>
|
||||
public async Task<RenderResult> RenderAsync(RenderInput input, RenderTarget target, RenderOptions? options = null, IProgress<RenderProgress>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var corrections = await RenderPreparation.PrepareAsync(input, options, progress, cancellationToken).ConfigureAwait(false);
|
||||
return await RenderAsync(input, corrections, target, options, progress, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>Renders one target with corrections prepared earlier (shared by a batch).</summary>
|
||||
/// <exception cref="RenderException">No encoder can produce the target, or every frame is excluded.</exception>
|
||||
public async Task<RenderResult> RenderAsync(RenderInput input, RenderCorrections corrections, RenderTarget target, RenderOptions? options = null,
|
||||
IProgress<RenderProgress>? progress = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
ArgumentNullException.ThrowIfNull(corrections);
|
||||
ArgumentNullException.ThrowIfNull(target);
|
||||
options ??= RenderOptions.Default;
|
||||
if (corrections.FrameCount != input.Source.FrameCount) throw new ArgumentException("The corrections belong to another sequence.", nameof(corrections));
|
||||
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var setup = Setup(input, target, options, corrections);
|
||||
if (!setup.Encoder.IsReady)
|
||||
{
|
||||
var notice = setup.Encoder.Notices.LastOrDefault() ?? new EncoderNotice(EncoderNotices.NoEncoder, setup.Encoder.Settings.Codec.ToString());
|
||||
throw new RenderException(notice.Key, $"No encoder can produce {target.Export.Codec} here ({setup.Encoder.Status})", notice.Args);
|
||||
}
|
||||
if (setup.Plan.Frames.Count == 0) throw new RenderException("Export.Render.NoFrames", "Every frame is excluded.");
|
||||
using var run = new RenderRun(input, corrections, setup, options, progress);
|
||||
return await run.ExecuteAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders several targets of one sequence one after the other, preparing the sequence once. A failing target is
|
||||
/// reported and the batch continues; cancellation stops the batch.
|
||||
/// </summary>
|
||||
public async Task<IReadOnlyList<BatchItemResult>> RenderBatchAsync(RenderInput input, IReadOnlyList<RenderTarget> targets, RenderOptions? options = null,
|
||||
IProgress<RenderProgress>? progress = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(targets);
|
||||
var corrections = await RenderPreparation.PrepareAsync(input, options, progress, cancellationToken).ConfigureAwait(false);
|
||||
var results = new List<BatchItemResult>(targets.Count);
|
||||
foreach (var target in targets)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
try
|
||||
{
|
||||
results.Add(new BatchItemResult(target, await RenderAsync(input, corrections, target, options, progress, cancellationToken).ConfigureAwait(false), null));
|
||||
}
|
||||
catch (Exception ex) when (!(ex is OperationCanceledException && cancellationToken.IsCancellationRequested))
|
||||
{
|
||||
Log.Warning(LogCategory, $"Batch target {target.OutputPath} failed", ex);
|
||||
results.Add(new BatchItemResult(target, null, ex));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>State of one render: caches, flow, stacking, the encoder session and the encode in flight.</summary>
|
||||
internal sealed class RenderRun : IDisposable
|
||||
{
|
||||
/// <summary>Largest speed (source frames per output period) that scales motion blur; faster plans blur no further.</summary>
|
||||
private const double MaxBlurSpeed = 4;
|
||||
|
||||
private readonly RenderInput _input;
|
||||
private readonly RenderCorrections _corrections;
|
||||
private readonly RenderSetup _setup;
|
||||
private readonly RenderOptions _options;
|
||||
private readonly IProgress<RenderProgress>? _progress;
|
||||
private readonly RenderPlan _plan;
|
||||
private readonly RenderGeometry _geometry;
|
||||
private readonly PreparedFrameCache _prepared;
|
||||
private readonly FlowCache _flows = new(2);
|
||||
private readonly MotionBlurRenderer _blur = new();
|
||||
private readonly List<RenderWarning> _warnings = [];
|
||||
private readonly Stopwatch _clock = new();
|
||||
private readonly int _workingEdge;
|
||||
private readonly float? _knee;
|
||||
private readonly double _targetShutter;
|
||||
private readonly FlowQuality _flowQuality;
|
||||
private OpticalFlowEngine? _flowEngine;
|
||||
private RegionMask? _mask;
|
||||
private IVideoEncoderSession? _session;
|
||||
private Task? _encoding;
|
||||
private int _done;
|
||||
|
||||
public RenderRun(RenderInput input, RenderCorrections corrections, RenderSetup setup, RenderOptions options, IProgress<RenderProgress>? progress)
|
||||
{
|
||||
_input = input;
|
||||
_corrections = corrections;
|
||||
_setup = setup;
|
||||
_options = options;
|
||||
_progress = progress;
|
||||
_plan = setup.Plan;
|
||||
_geometry = setup.Geometry;
|
||||
_prepared = new PreparedFrameCache(int.Max(3, options.CacheFrames));
|
||||
_workingEdge = _geometry.WorkingLongEdge;
|
||||
var exposure = input.Project.Exposure;
|
||||
if (exposure.HighlightKnee is { } knee)
|
||||
{
|
||||
if (knee is > 0 and < 1) _knee = (float)knee;
|
||||
else _warnings.Add(new RenderWarning("Export.Render.KneeIgnored", knee.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
var motion = input.Project.Motion;
|
||||
_targetShutter = double.Clamp(motion.TargetShutterAngle.Resolve(180.0), 0, 360);
|
||||
_flowQuality = motion.FlowQuality.Resolve(options.DefaultFlowQuality) switch
|
||||
{
|
||||
FlowQualitySetting.Draft => FlowQuality.Draft,
|
||||
FlowQualitySetting.Best => FlowQuality.Best,
|
||||
_ => FlowQuality.Balanced,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<RenderResult> ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var settings = _setup.Encoder.Settings;
|
||||
_clock.Start();
|
||||
Log.Info(RenderPipeline.LogCategory, $"Rendering {_plan.Frames.Count} frames ({_plan.SlotCount} periods) to {settings.Codec} {settings.Width}×{settings.Height} @ {settings.FrameRate}: {settings.OutputPath}");
|
||||
var session = _session = _setup.Encoder.Open();
|
||||
try
|
||||
{
|
||||
await RenderFramesAsync(cancellationToken).ConfigureAwait(false);
|
||||
await FlushEncodingAsync().ConfigureAwait(false);
|
||||
_progress?.Report(new RenderProgress(RenderStage.Finishing, _done, _plan.Frames.Count, Fps(), _clock.Elapsed, TimeSpan.Zero));
|
||||
session.Complete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ObserveEncodingAsync().ConfigureAwait(false);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
session.Dispose();
|
||||
}
|
||||
_clock.Stop();
|
||||
var warnings = new List<RenderWarning>(_setup.Warnings);
|
||||
warnings.AddRange(_corrections.Report.Warnings);
|
||||
warnings.AddRange(_warnings);
|
||||
var result = new RenderResult
|
||||
{
|
||||
OutputPath = settings.OutputPath,
|
||||
PresetId = _setup.Target.Export.PresetId,
|
||||
Codec = settings.Codec,
|
||||
Width = settings.Width,
|
||||
Height = settings.Height,
|
||||
FrameRate = settings.FrameRate,
|
||||
DurationSeconds = _plan.DurationSeconds,
|
||||
FrameCount = _plan.Frames.Count,
|
||||
Bytes = RenderResult.SizeOf(settings.OutputPath),
|
||||
EncoderName = session.EncoderName,
|
||||
Hardware = session.IsHardware,
|
||||
Elapsed = _clock.Elapsed,
|
||||
Warnings = warnings,
|
||||
};
|
||||
Log.Info(RenderPipeline.LogCategory, $"Rendered {result.FrameCount} frames in {result.Elapsed.TotalSeconds:F1} s with {result.EncoderName}: {result.Bytes} bytes");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_prepared.Dispose();
|
||||
_flows.Dispose();
|
||||
_flowEngine?.Dispose();
|
||||
}
|
||||
|
||||
private async Task RenderFramesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var stack = _input.Project.Stack;
|
||||
switch (stack.Mode)
|
||||
{
|
||||
case StackSetting.Median or StackSetting.Mean:
|
||||
await RenderWindowStackAsync(stack, cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case StackSetting.StarTrails:
|
||||
using (var trails = new StarTrailStacker(StarTrailStacker.DecayForTrailLength(stack.Length > 0 ? stack.Length : double.PositiveInfinity)))
|
||||
{
|
||||
foreach (var planned in _plan.Frames)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
using (var frame = await RenderFrameAsync(planned, blur: false, cancellationToken).ConfigureAwait(false)) trails.Add(frame);
|
||||
await EmitAsync(trails.Result!.Clone(), planned.Duration90k).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
foreach (var planned in _plan.Frames)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var frame = await RenderFrameAsync(planned, _setup.MotionBlur, cancellationToken).ConfigureAwait(false);
|
||||
await EmitAsync(frame, planned.Duration90k).ConfigureAwait(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Centred median/mean window: output k is emitted once frame k + half has been pushed (the tail reuses the
|
||||
/// last full window).</summary>
|
||||
private async Task RenderWindowStackAsync(StackSettings stack, CancellationToken cancellationToken)
|
||||
{
|
||||
var window = int.Max(1, stack.Length);
|
||||
var half = (window - 1) / 2;
|
||||
using var stacker = new TemporalStacker(window, stack.Mode == StackSetting.Median ? StackMode.Median : StackMode.Mean);
|
||||
var pending = new Queue<PlannedFrame>();
|
||||
foreach (var planned in _plan.Frames)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
using (var frame = await RenderFrameAsync(planned, blur: false, cancellationToken).ConfigureAwait(false)) stacker.Push(frame);
|
||||
pending.Enqueue(planned);
|
||||
if (pending.Count > half) await EmitStackAsync(stacker, pending.Dequeue(), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
while (pending.Count > 0) await EmitStackAsync(stacker, pending.Dequeue(), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task EmitStackAsync(TemporalStacker stacker, PlannedFrame planned, CancellationToken cancellationToken)
|
||||
{
|
||||
var output = new ImageBuffer(_geometry.OutputWidth, _geometry.OutputHeight, 3, clear: false);
|
||||
try
|
||||
{
|
||||
stacker.Render(output, cancellationToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
output.Dispose();
|
||||
throw;
|
||||
}
|
||||
await EmitAsync(output, planned.Duration90k).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>The picture of one planned frame at the output size (a new buffer owned by the caller).</summary>
|
||||
private async Task<ImageBuffer> RenderFrameAsync(PlannedFrame planned, bool blur, CancellationToken cancellationToken)
|
||||
{
|
||||
if (planned.Fraction == 0)
|
||||
{
|
||||
var frame = await PreparedAsync(planned.From, cancellationToken).ConfigureAwait(false);
|
||||
if (blur && BlurPair(planned.From) is { } pair && BlurFraction(pair.From, pair.To, planned.Speed) is var fraction and > 0)
|
||||
{
|
||||
var flows = await FlowAsync(pair.From, pair.To, needBackward: false, cancellationToken).ConfigureAwait(false);
|
||||
frame = await PreparedAsync(planned.From, cancellationToken).ConfigureAwait(false);
|
||||
return Blurred(frame, flows.Forward, fraction, cancellationToken);
|
||||
}
|
||||
return frame.Clone();
|
||||
}
|
||||
|
||||
var pairFlows = await FlowAsync(planned.From, planned.To, needBackward: true, cancellationToken).ConfigureAwait(false);
|
||||
var a = await PreparedAsync(planned.From, cancellationToken).ConfigureAwait(false);
|
||||
var b = await PreparedAsync(planned.To, cancellationToken).ConfigureAwait(false);
|
||||
var synthesised = new ImageBuffer(a.Width, a.Height, a.Channels, clear: false);
|
||||
try
|
||||
{
|
||||
FrameInterpolator.Synthesize(a, b, pairFlows.Forward, pairFlows.Backward!, planned.Fraction, synthesised, cancellationToken: cancellationToken);
|
||||
var fraction = blur ? BlurFraction(planned.From, planned.To, planned.Speed) : 0;
|
||||
if (fraction <= 0) return synthesised;
|
||||
using (synthesised) return Blurred(synthesised, pairFlows.Forward, fraction, cancellationToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
synthesised.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private ImageBuffer Blurred(ImageBuffer source, MotionField flow, double fraction, CancellationToken cancellationToken)
|
||||
{
|
||||
var output = new ImageBuffer(source.Width, source.Height, source.Channels, clear: false);
|
||||
try
|
||||
{
|
||||
_blur.Render(source, flow, fraction, output, cancellationToken);
|
||||
return output;
|
||||
}
|
||||
catch
|
||||
{
|
||||
output.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Continuous neighbours whose flow describes the motion at <paramref name="index"/>.</summary>
|
||||
private (int From, int To)? BlurPair(int index)
|
||||
{
|
||||
var next = _plan.NextContinuous(index);
|
||||
if (next >= 0) return (index, next);
|
||||
var previous = _plan.PreviousContinuous(index);
|
||||
return previous >= 0 ? (previous, index) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fraction of the <paramref name="from"/>→<paramref name="to"/> flow to smear: the target shutter is relative to the
|
||||
/// output period, which spans <paramref name="speed"/> source intervals, and the camera's own exposure already
|
||||
/// blurred <see cref="ShutterAngle.FromExposure"/> of one interval (√(target² − real²) composition, §11.1).
|
||||
/// </summary>
|
||||
private double BlurFraction(int from, int to, double speed)
|
||||
{
|
||||
var steps = to - from;
|
||||
if (steps <= 0) return 0;
|
||||
var real = 0.0;
|
||||
var info = _input.Frames[from];
|
||||
if (info.ExposureTime is > 0 and var exposure && info.CapturedAt is { } t0 && _input.Frames[to].CapturedAt is { } t1 && t1 > t0)
|
||||
real = double.Min(360, ShutterAngle.FromExposure(exposure, (t1 - t0).TotalSeconds / steps));
|
||||
return ShutterAngle.BlurFraction(_targetShutter * double.Clamp(double.Abs(speed), 0, MaxBlurSpeed), real) / steps;
|
||||
}
|
||||
|
||||
private async Task<FlowPair> FlowAsync(int from, int to, bool needBackward, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_flows.TryGet(from, to, needBackward, out var cached)) return cached;
|
||||
var a = await PreparedAsync(from, cancellationToken).ConfigureAwait(false);
|
||||
var b = await PreparedAsync(to, cancellationToken).ConfigureAwait(false);
|
||||
_flowEngine ??= new OpticalFlowEngine(_flowQuality);
|
||||
FlowPair flows;
|
||||
if (needBackward)
|
||||
{
|
||||
var (forward, backward) = _flowEngine.ComputeBidirectional(a, b, cancellationToken);
|
||||
flows = new FlowPair(forward, backward);
|
||||
}
|
||||
else
|
||||
{
|
||||
flows = new FlowPair(_flowEngine.Compute(a, b, cancellationToken), null);
|
||||
}
|
||||
_flows.Add(from, to, flows);
|
||||
return flows;
|
||||
}
|
||||
|
||||
/// <summary>Source frame <paramref name="index"/> decoded, exposure-corrected and warped to the output size (cached).</summary>
|
||||
private async Task<ImageBuffer> PreparedAsync(int index, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_prepared.TryGet(index, out var cached)) return cached;
|
||||
var raw = await _input.Source.GetFrameAsync(index, _workingEdge, DecodePurpose.Render, cancellationToken).ConfigureAwait(false);
|
||||
ImageBuffer prepared;
|
||||
try
|
||||
{
|
||||
raw = Rgb(raw);
|
||||
ApplyExposure(raw, index);
|
||||
var settings = _geometry.For(raw.Width, raw.Height, index, _corrections.StabilizationAt(index, raw.Width, raw.Height));
|
||||
prepared = GeometryStage.Apply(raw, settings, cancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
raw.Dispose();
|
||||
}
|
||||
_prepared.Add(index, prepared);
|
||||
return prepared;
|
||||
}
|
||||
|
||||
/// <summary>Gray sources become RGB and alpha is dropped, so every stage and encoder sees three channels.</summary>
|
||||
private static ImageBuffer Rgb(ImageBuffer frame)
|
||||
{
|
||||
if (frame.Channels == 3) return frame;
|
||||
using (frame)
|
||||
{
|
||||
if (frame.Channels == 1) return PixelConvert.GrayToRgb(frame);
|
||||
var rgb = new ImageBuffer(frame.Width, frame.Height, 3, clear: false);
|
||||
frame.Data[..(3 * frame.PlaneLength)].CopyTo(rgb.Data);
|
||||
return rgb;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyExposure(ImageBuffer frame, int index)
|
||||
{
|
||||
var gains = _corrections.WhiteBalance?[index];
|
||||
if (_corrections is { Regions: { } mask, SkyEv: { } sky, LandEv: { } land })
|
||||
{
|
||||
if (_mask is null || _mask.Width != frame.Width || _mask.Height != frame.Height) _mask = mask.Resample(frame.Width, frame.Height);
|
||||
ExposureProcessor.ApplyRegion(frame, _mask.Sky, sky[index], land[index], gains);
|
||||
return;
|
||||
}
|
||||
var ev = _corrections.ExposureEv[index];
|
||||
if (ev != 0 || (gains is { } g && g != ChannelGains.Identity)) ExposureProcessor.Apply(frame, ev, gains);
|
||||
}
|
||||
|
||||
/// <summary>Applies the knee and hands the frame to the encoder once the previous frame is encoded; owns <paramref name="frame"/>.</summary>
|
||||
private async Task EmitAsync(ImageBuffer frame, long duration90k)
|
||||
{
|
||||
ImageBuffer? preview = null;
|
||||
try
|
||||
{
|
||||
await FlushEncodingAsync().ConfigureAwait(false);
|
||||
if (_knee is { } knee) ExposureProcessor.Apply(frame, 0, null, knee);
|
||||
_done++;
|
||||
if (_options.PreviewInterval > 0 && (_done - 1) % _options.PreviewInterval == 0) preview = Resampler.Thumbnail(frame, _options.PreviewLongEdge);
|
||||
}
|
||||
catch
|
||||
{
|
||||
frame.Dispose();
|
||||
throw;
|
||||
}
|
||||
var session = _session!;
|
||||
_encoding = Task.Run(() =>
|
||||
{
|
||||
using (frame) session.WriteFrame(frame, duration90k);
|
||||
}, CancellationToken.None);
|
||||
if (_progress is not null)
|
||||
{
|
||||
var fps = Fps();
|
||||
_progress.Report(new RenderProgress(RenderStage.Rendering, _done, _plan.Frames.Count, fps, _clock.Elapsed,
|
||||
fps > 0 ? TimeSpan.FromSeconds((_plan.Frames.Count - _done) / fps) : null, preview));
|
||||
}
|
||||
else
|
||||
{
|
||||
preview?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private double Fps() => _done / double.Max(_clock.Elapsed.TotalSeconds, 1e-6);
|
||||
|
||||
/// <summary>Waits for the encode in flight; its failure propagates here (once).</summary>
|
||||
private async Task FlushEncodingAsync()
|
||||
{
|
||||
var encoding = _encoding;
|
||||
_encoding = null;
|
||||
if (encoding is not null) await encoding.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>After a failure: waits for the encode in flight and logs (never throws) a second error.</summary>
|
||||
private async Task ObserveEncodingAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await FlushEncodingAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(RenderPipeline.LogCategory, "The encoder also failed while the render was stopping", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user