Files
Chronos/src/Titano.App/Settings/EncoderUse.cs
T
Claude 9b8b4f257d test(app): chips by where the originals are, this PC's workers, row names and encoder use
Drops the unreachable "Custom only" text: every codec of this PC has built-in presets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-05 22:03:43 +00:00

54 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Titano.Core.Export;
using Titano.Core.Localization;
using Titano.Core.Video;
namespace Titano.App.Settings;
/// <summary>Who provides an encoder row.</summary>
public enum EncoderSource
{
/// <summary>A Media Foundation MFT (hardware or Microsoft software).</summary>
MediaFoundation,
/// <summary>Titano's managed MJPEG/AVI writer.</summary>
BuiltInMjpeg,
/// <summary>Titano's managed GIF/APNG encoders.</summary>
BuiltInAnimation,
}
/// <summary>One row of Settings › Rendering › Encoders.</summary>
public sealed record EncoderRow(string Codec, string Name, string? Vendor, EncoderSource Source, bool Hardware, bool TenBit, int MaxWidth, int MaxHeight, VideoCodec? VideoCodec)
{
public bool CanSelfTest => Source != EncoderSource.BuiltInAnimation;
/// <summary>"NVIDIA · NVIDIA HEVC Encoder MFT" unless the name already carries the vendor.</summary>
public string DisplayName => Vendor is { } vendor && !Name.Contains(vendor, StringComparison.OrdinalIgnoreCase) ? vendor + " · " + Name : Name;
}
/// <summary>What the encoders of this PC are for: the built-in presets each one serves and what a render node offers.</summary>
public static class EncoderUse
{
/// <summary>Names of the built-in presets an encoder row can encode, in preset order.</summary>
public static IReadOnlyList<string> Presets(EncoderRow row) =>
[
.. ExportPresets.BuiltIn
.Where(p => row.Source == EncoderSource.BuiltInAnimation ? p.Codec is VideoCodec.Gif or VideoCodec.Apng : p.Codec == row.VideoCodec)
.Select(p => Loc.L(p.NameKey)),
];
/// <summary>"4K archive · 4K HEVC · …" for the Used for column (every codec of this PC has built-in presets).</summary>
public static string Text(EncoderRow row) => string.Join(" · ", Presets(row));
/// <summary>
/// The Media Foundation encoders a render node on this PC offers the server: the software ones, and the hardware ones
/// when its renders may use them (<paramref name="allowsHardware"/>, as the node client decides).
/// </summary>
public static IReadOnlyList<EncoderRow> Node(IEnumerable<EncoderRow> rows, bool allowsHardware) =>
[.. rows.Where(r => r.Source == EncoderSource.MediaFoundation && (!r.Hardware || allowsHardware))];
/// <summary>"HEVC · H.264 · AV1": the codecs of <paramref name="encoders"/>, each once; null when there are none.</summary>
public static string? Codecs(IEnumerable<EncoderRow> encoders) =>
encoders.Select(e => e.Codec).Distinct(StringComparer.Ordinal).ToList() is { Count: > 0 } codecs ? string.Join(" · ", codecs) : null;
}