Files
Chronos/tests/Chronos.Core.Tests/Render/CapturingEncoderProvider.cs
T
Alby96andClaude Opus 5.5 728ffa35cb
CI / Build and test (push) Successful in 9m41s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 14m49s
CI / PostgreSQL 16 integration (push) Successful in 8m51s
CI / PostgreSQL 17 integration (push) Successful in 9m48s
CI / Docker image (push) Successful in 54s
Release / Server image (push) Successful in 1m39s
feat: export panel and Render menu, playback options, videos library (owner review 1 phase 5) (#27)
Owner review 1 R3, R8, R9. A grouped Export step and Render menu; encoding, playback (reverse, boomerang, loops, fades, hold) and still frames; one videos library on the desktop and the server with a verified trash and copies to a videos folder.

Closes #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-05 09:18:40 +01:00

64 lines
2.6 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; }
/// <summary>The settings each session says it did not take (<see cref="IVideoEncoderSession.Ignored"/>).</summary>
public IReadOnlyList<EncoderSetting> Ignores { 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;
public IReadOnlyList<EncoderSetting> Ignored => owner.Ignores;
}
}