Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 5s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 8s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 54s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m48s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 12m49s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 14m35s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 18m11s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 13m23s
Make the ~14 health checks actionable: each check that has a fix now declares
where to go, and the SPA acts on it.
Backend:
- Widen domain HealthCheckLink (string Link) -> (string Target, HealthCheckLinkKind
Kind) with ExternalDoc|AppRoute + factories; only the 4 link-building checks and
the API mapper touched .Link.
- Evolve HealthCheckResponseModel additively (/api/v1 frozen-additive): keep
deprecated string? Link (still populated), add Brief (the BriefMessage the mapper
was silently dropping) and nested Remediation {Kind, Target}. Kind is a mapped
string, not a wire enum.
- Make Mapper.GetStatus total: NotApplicable no longer throws (defensive; handler
still filters it). InternalsVisibleTo(ErsatzTV.Tests) added to unit-test totality.
- Fix 2 stale Blazor route links (media/trash -> /app/trash, search?query ->
/app/search); add AppRoute remediation to actionable checks that had none
(libraries / schedules / ffmpeg-profiles / settings).
SPA:
- DashboardScreen health panel renders remediation: AppRoute -> client-side nav
button, ExternalDoc -> new-tab anchor; detail text truncates with title-hover.
- Remove the dead "Open Classic UI" -> /system/health row from SettingsScreen
(a #91b leftover that just 302'd to /app); update its regression test.
Docs: decisions.md (#164), api-conventions.md (deprecate-in-place DTO evolution),
blazor-route-parity.md (Section 4 correction); v1.json/v1.d.ts/endpoint-index
regenerated.
fixes #164
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
161 lines
6.1 KiB
C#
161 lines
6.1 KiB
C#
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Health;
|
|
using ErsatzTV.Core.Health.Checks;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using ErsatzTV.FFmpeg.Runtime;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using LanguageExt.UnsafeValueAccess;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ErsatzTV.Infrastructure.Health.Checks;
|
|
|
|
public class HardwareAccelerationHealthCheck : BaseHealthCheck, IHardwareAccelerationHealthCheck
|
|
{
|
|
private static readonly string[] FFmpegAccelsArguments = { "-v", "quiet", "-hwaccels" };
|
|
private static readonly string[] FFmpegEncodersArguments = { "-v", "quiet", "-encoders" };
|
|
|
|
private readonly IConfigElementRepository _configElementRepository;
|
|
private readonly IDbContextFactory<TvContext> _dbContextFactory;
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
public HardwareAccelerationHealthCheck(
|
|
IDbContextFactory<TvContext> dbContextFactory,
|
|
IConfigElementRepository configElementRepository,
|
|
IRuntimeInfo runtimeInfo)
|
|
{
|
|
_dbContextFactory = dbContextFactory;
|
|
_configElementRepository = configElementRepository;
|
|
_runtimeInfo = runtimeInfo;
|
|
}
|
|
|
|
public override string Title => "Hardware Acceleration";
|
|
|
|
public async Task<HealthCheckResult> Check(CancellationToken cancellationToken)
|
|
{
|
|
Option<ConfigElement> maybeFFmpegPath =
|
|
await _configElementRepository.GetConfigElement(ConfigElementKey.FFmpegPath, cancellationToken);
|
|
if (maybeFFmpegPath.IsNone)
|
|
{
|
|
return FailResult("Unable to locate ffmpeg", "Unable to locate ffmpeg");
|
|
}
|
|
|
|
string version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|
|
?.InformationalVersion ?? "unknown";
|
|
|
|
var accelerationKinds = new List<HardwareAccelerationKind>();
|
|
|
|
if (version.Contains("docker", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
if (version.Contains("nvidia", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
accelerationKinds.Add(HardwareAccelerationKind.Nvenc);
|
|
}
|
|
else if (version.Contains("vaapi", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
accelerationKinds.Add(HardwareAccelerationKind.Vaapi);
|
|
accelerationKinds.Add(HardwareAccelerationKind.Qsv);
|
|
}
|
|
}
|
|
|
|
if (accelerationKinds.Count == 0)
|
|
{
|
|
accelerationKinds.AddRange(
|
|
await GetSupportedAccelerationKinds(maybeFFmpegPath.ValueUnsafe().Value, cancellationToken));
|
|
}
|
|
|
|
if (accelerationKinds.Count == 0)
|
|
{
|
|
return InfoResult(
|
|
"No compatible hardware acceleration kinds are supported by ffmpeg",
|
|
"FFmpeg does not support hardware acceleration");
|
|
}
|
|
|
|
Option<HealthCheckResult> maybeResult = await VerifyProfilesUseAcceleration(accelerationKinds);
|
|
foreach (HealthCheckResult result in maybeResult)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return OkResult();
|
|
}
|
|
|
|
private async Task<Option<HealthCheckResult>> VerifyProfilesUseAcceleration(
|
|
IEnumerable<HardwareAccelerationKind> accelerationKinds)
|
|
{
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
|
|
|
|
List<Channel> badChannels = await dbContext.Channels
|
|
.Filter(c => c.StreamingMode != StreamingMode.HttpLiveStreamingDirect)
|
|
.Filter(c => !accelerationKinds.Contains(c.FFmpegProfile.HardwareAcceleration))
|
|
.ToListAsync();
|
|
|
|
if (badChannels.Count != 0)
|
|
{
|
|
var accel = string.Join(", ", accelerationKinds);
|
|
var channels = string.Join(", ", badChannels.Map(c => $"{c.Number} - {c.Name}"));
|
|
return WarningResult(
|
|
$"The following channels use ffmpeg profiles that are not configured for hardware acceleration ({accel}): {channels}",
|
|
$"{badChannels.Count} channels are not configured for hardware acceleration",
|
|
HealthCheckLink.AppRoute("/app/ffmpeg-profiles"));
|
|
}
|
|
|
|
return None;
|
|
}
|
|
|
|
private async Task<List<HardwareAccelerationKind>> GetSupportedAccelerationKinds(
|
|
string ffmpegPath,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var result = new System.Collections.Generic.HashSet<HardwareAccelerationKind>();
|
|
|
|
string output = await GetProcessOutput(ffmpegPath, FFmpegAccelsArguments, cancellationToken);
|
|
foreach (string method in output.Split("\n").Map(s => s.Trim()).Skip(1))
|
|
{
|
|
switch (method)
|
|
{
|
|
case "vaapi":
|
|
result.Add(HardwareAccelerationKind.Vaapi);
|
|
break;
|
|
case "nvenc":
|
|
result.Add(HardwareAccelerationKind.Nvenc);
|
|
break;
|
|
case "cuda":
|
|
result.Add(HardwareAccelerationKind.Nvenc);
|
|
break;
|
|
case "qsv":
|
|
result.Add(HardwareAccelerationKind.Qsv);
|
|
break;
|
|
case "videotoolbox":
|
|
result.Add(HardwareAccelerationKind.VideoToolbox);
|
|
break;
|
|
case "rkmpp":
|
|
result.Add(HardwareAccelerationKind.Rkmpp);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// not real ffmpeg hwaccels, but have hw encoders that we can use
|
|
string output2 = await GetProcessOutput(
|
|
ffmpegPath,
|
|
FFmpegEncodersArguments,
|
|
cancellationToken);
|
|
foreach (string encoder in output2.Split("\n").Map(s => s.Trim()))
|
|
{
|
|
if (_runtimeInfo.IsOSPlatform(OSPlatform.Windows) && encoder.Contains("_amf "))
|
|
{
|
|
result.Add(HardwareAccelerationKind.Amf);
|
|
}
|
|
|
|
// TODO: fix and enable V4L2 M2M
|
|
// else if (_runtimeInfo.IsOSPlatform(OSPlatform.Linux) && encoder.Contains("_v4l2m2m "))
|
|
// {
|
|
// result.Add(HardwareAccelerationKind.V4l2m2m);
|
|
// }
|
|
}
|
|
|
|
return result.ToList();
|
|
}
|
|
}
|