CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
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. 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) and pe-check. 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>
147 lines
7.5 KiB
C#
147 lines
7.5 KiB
C#
using Chronos.Core.Export;
|
||
using Chronos.Core.Tests.Render;
|
||
using Chronos.Core.Video;
|
||
using Chronos.Core.Video.Managed;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.Core.Tests.Export;
|
||
|
||
public sealed class EncoderSelectorTests
|
||
{
|
||
private static readonly EncoderCapability SoftwareH264 = new(VideoCodec.H264, "Microsoft H.264", false, 4096, 2304, false);
|
||
private static readonly EncoderCapability HardwareH264 = new(VideoCodec.H264, "NVENC H.264", true, 4096, 4096, false, "NVIDIA");
|
||
private static readonly EncoderCapability HardwareHevc = new(VideoCodec.Hevc, "NVENC HEVC", true, 8192, 8192, true, "NVIDIA");
|
||
private static readonly EncoderCapability HardwareHevc8 = new(VideoCodec.Hevc, "QSV HEVC", true, 8192, 8192, false, "Intel");
|
||
|
||
private static EncodeSettings Request(VideoCodec codec, int width = 3840, int height = 2160, int bitDepth = 8, long bitRate = 20_000_000, Rational? fps = null) => new()
|
||
{
|
||
OutputPath = "/exports/out" + VideoCodecInfo.FileExtension(codec),
|
||
Codec = codec,
|
||
Width = width,
|
||
Height = height,
|
||
FrameRate = fps ?? new Rational(30, 1),
|
||
BitDepth = bitDepth,
|
||
BitRate = bitRate,
|
||
Profile = bitDepth == 10 ? CodecProfile.HevcMain10 : CodecProfile.Auto,
|
||
};
|
||
|
||
private static IVideoEncoderProvider[] Client(params EncoderCapability[] capabilities) =>
|
||
[new CapturingEncoderProvider("Media Foundation", capabilities), new ManagedEncoderProvider()];
|
||
|
||
[Test]
|
||
public void ManagedCodecsUseTheManagedProviderEverywhere()
|
||
{
|
||
foreach (var host in new[] { EncoderHost.Client, EncoderHost.Server })
|
||
{
|
||
var selection = EncoderSelector.Select(Request(VideoCodec.Mjpeg, bitDepth: 8), Client(HardwareH264), host);
|
||
Assert.True(selection.IsReady);
|
||
Assert.Equal(ManagedEncoderProvider.ProviderName, selection.Provider!.Name);
|
||
Assert.Equal("Managed MJPEG", selection.Capability!.Name);
|
||
Assert.Empty(selection.Notices);
|
||
}
|
||
}
|
||
|
||
[Test]
|
||
public void ManagedBitDepthsAreAdjustedWithANotice()
|
||
{
|
||
var png = EncoderSelector.Select(Request(VideoCodec.PngSequence, bitDepth: 10), [new ManagedEncoderProvider()], EncoderHost.Server);
|
||
Assert.Equal(16, png.Settings.BitDepth);
|
||
Assert.Equal(EncoderNotices.BitDepthAdjusted, png.Notices.Single().Key);
|
||
Assert.SequenceEqual(new[] { "10", "16" }, png.Notices.Single().Args);
|
||
var jpeg = EncoderSelector.Select(Request(VideoCodec.JpegSequence, bitDepth: 16), [new ManagedEncoderProvider()], EncoderHost.Server);
|
||
Assert.Equal(8, jpeg.Settings.BitDepth);
|
||
}
|
||
|
||
[Test]
|
||
public void ServerNeedsARenderNodeForMp4()
|
||
{
|
||
var selection = EncoderSelector.Select(Request(VideoCodec.H264), [new ManagedEncoderProvider()], EncoderHost.Server);
|
||
Assert.Equal(EncoderSelectionStatus.NeedsRenderNode, selection.Status);
|
||
Assert.Null(selection.Provider);
|
||
Assert.Equal(EncoderNotices.NeedsRenderNode, selection.Notices.Single().Key);
|
||
Assert.Throws<InvalidOperationException>(() => selection.Open());
|
||
}
|
||
|
||
[Test]
|
||
public void HardwareIsPreferredUnlessSoftwareIsAsked()
|
||
{
|
||
var providers = Client(SoftwareH264, HardwareH264);
|
||
var hardware = EncoderSelector.Select(Request(VideoCodec.H264), providers, EncoderHost.Client);
|
||
Assert.True(hardware.IsReady);
|
||
Assert.Equal("NVENC H.264", hardware.Capability!.Name);
|
||
Assert.Empty(hardware.Notices);
|
||
Assert.Equal(new CodecLevel(VideoCodec.H264, 5, 1), hardware.Level);
|
||
|
||
var software = EncoderSelector.Select(Request(VideoCodec.H264) with { PreferHardware = false }, providers, EncoderHost.Client);
|
||
Assert.Equal("Microsoft H.264", software.Capability!.Name);
|
||
|
||
var named = EncoderSelector.Select(Request(VideoCodec.H264) with { EncoderName = "Microsoft H.264" }, providers, EncoderHost.Client);
|
||
Assert.Equal("Microsoft H.264", named.Capability!.Name);
|
||
Assert.Equal(EncoderNotices.SoftwareOnly, named.Notices.Single().Key);
|
||
}
|
||
|
||
[Test]
|
||
public void HevcFallsBackToH264WhenNoEncoderExists()
|
||
{
|
||
var selection = EncoderSelector.Select(Request(VideoCodec.Hevc, bitDepth: 10, bitRate: 14_000_000), Client(SoftwareH264), EncoderHost.Client);
|
||
Assert.True(selection.IsReady);
|
||
Assert.Equal(VideoCodec.H264, selection.Settings.Codec);
|
||
Assert.Equal(8, selection.Settings.BitDepth);
|
||
Assert.Equal(CodecProfile.H264High, selection.Settings.Profile);
|
||
Assert.Equal(20_000_000L, selection.Settings.BitRate);
|
||
Assert.Equal(EncoderNotices.FallbackToH264, selection.Notices[0].Key);
|
||
Assert.SequenceEqual(new[] { "Hevc" }, selection.Notices[0].Args);
|
||
Assert.Contains(selection.Notices, n => n.Key == EncoderNotices.SoftwareOnly);
|
||
Assert.Equal(".mp4", Path.GetExtension(selection.Settings.OutputPath));
|
||
}
|
||
|
||
[Test]
|
||
public void TenBitNeedsATenBitEncoder()
|
||
{
|
||
var eightOnly = EncoderSelector.Select(Request(VideoCodec.Hevc, bitDepth: 10), Client(HardwareHevc8), EncoderHost.Client);
|
||
Assert.Equal(8, eightOnly.Settings.BitDepth);
|
||
Assert.Equal(CodecProfile.HevcMain, eightOnly.Settings.Profile);
|
||
Assert.Equal(EncoderNotices.TenBitUnavailable, eightOnly.Notices.Single().Key);
|
||
|
||
var tenBit = EncoderSelector.Select(Request(VideoCodec.Hevc, bitDepth: 10), Client(HardwareHevc8, HardwareHevc), EncoderHost.Client);
|
||
Assert.Equal("NVENC HEVC", tenBit.Capability!.Name);
|
||
Assert.Equal(10, tenBit.Settings.BitDepth);
|
||
Assert.Empty(tenBit.Notices);
|
||
}
|
||
|
||
[Test]
|
||
public void SizeIsCappedByEncoderAndLevel()
|
||
{
|
||
var encoder = EncoderSelector.Select(Request(VideoCodec.H264, 7680, 4320), Client(HardwareH264), EncoderHost.Client);
|
||
Assert.Equal((4096, 2304), (encoder.Settings.Width, encoder.Settings.Height));
|
||
Assert.Equal(EncoderNotices.ResolutionCappedByEncoder, encoder.Notices.Single().Key);
|
||
Assert.SequenceEqual(new[] { "NVENC H.264", "4096×2304" }, encoder.Notices.Single().Args);
|
||
|
||
var level = EncoderSelector.Select(Request(VideoCodec.Hevc, 7680, 4320, fps: new Rational(240, 1)), Client(HardwareHevc), EncoderHost.Client);
|
||
Assert.Equal(EncoderNotices.ResolutionCappedByLevel, level.Notices[0].Key);
|
||
Assert.Less(level.Settings.Width, 7680);
|
||
Assert.Equal(0, level.Settings.Width % 2);
|
||
Assert.Approximately(16.0 / 9, level.Settings.Width / (double)level.Settings.Height, 0.01);
|
||
Assert.True(CodecLimits.Check(VideoCodec.Hevc, level.Settings.Width, level.Settings.Height, 240, level.Settings.BitRate).Fits);
|
||
|
||
var odd = EncoderSelector.Select(Request(VideoCodec.H264, 1081, 607), Client(HardwareH264), EncoderHost.Client);
|
||
Assert.Equal((1080, 606), (odd.Settings.Width, odd.Settings.Height));
|
||
}
|
||
|
||
[Test]
|
||
public void BitRateIsCappedByTheHighestLevel()
|
||
{
|
||
var selection = EncoderSelector.Select(Request(VideoCodec.H264, 1920, 1080, bitRate: 2_000_000_000), Client(HardwareH264), EncoderHost.Client);
|
||
Assert.Equal(1_000_000_000L, selection.Settings.BitRate);
|
||
Assert.Equal(EncoderNotices.BitRateCapped, selection.Notices.Single().Key);
|
||
}
|
||
|
||
[Test]
|
||
public void NoVideoEncoderMeansUnavailable()
|
||
{
|
||
var selection = EncoderSelector.Select(Request(VideoCodec.Av1), [new ManagedEncoderProvider()], EncoderHost.Client);
|
||
Assert.Equal(EncoderSelectionStatus.Unavailable, selection.Status);
|
||
Assert.SequenceEqual(new[] { EncoderNotices.FallbackToH264, EncoderNotices.NoEncoder }, selection.Notices.Select(n => n.Key));
|
||
}
|
||
}
|