using Titano.Core.Export;
using Titano.Core.Localization;
using Titano.Core.Video;
namespace Titano.App.Settings;
/// Who provides an encoder row.
public enum EncoderSource
{
/// A Media Foundation MFT (hardware or Microsoft software).
MediaFoundation,
/// Titano's managed MJPEG/AVI writer.
BuiltInMjpeg,
/// Titano's managed GIF/APNG encoders.
BuiltInAnimation,
}
/// One row of Settings › Rendering › Encoders.
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;
/// "NVIDIA · NVIDIA HEVC Encoder MFT" unless the name already carries the vendor.
public string DisplayName => Vendor is { } vendor && !Name.Contains(vendor, StringComparison.OrdinalIgnoreCase) ? vendor + " · " + Name : Name;
}
/// What the encoders of this PC are for: the built-in presets each one serves and what a render node offers.
public static class EncoderUse
{
/// Names of the built-in presets an encoder row can encode, in preset order.
public static IReadOnlyList 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)),
];
/// "4K archive · 4K HEVC · …" for the Used for column (every codec of this PC has built-in presets).
public static string Text(EncoderRow row) => string.Join(" · ", Presets(row));
///
/// 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 (, as the node client decides).
///
public static IReadOnlyList Node(IEnumerable rows, bool allowsHardware) =>
[.. rows.Where(r => r.Source == EncoderSource.MediaFoundation && (!r.Hardware || allowsHardware))];
/// "HEVC · H.264 · AV1": the codecs of , each once; null when there are none.
public static string? Codecs(IEnumerable encoders) =>
encoders.Select(e => e.Codec).Distinct(StringComparer.Ordinal).ToList() is { Count: > 0 } codecs ? string.Join(" · ", codecs) : null;
}