mirror of https://github.com/ErsatzTV/ErsatzTV.git
				
				
			
				 25 changed files with 6758 additions and 57 deletions
			
			
		@ -1,45 +1,47 @@
				@@ -1,45 +1,47 @@
					 | 
				
			||||
using System; | 
				
			||||
using System.Reflection; | 
				
			||||
using System.Collections.Generic; | 
				
			||||
using System.Linq; | 
				
			||||
using System.Threading.Tasks; | 
				
			||||
using ErsatzTV.Core.Domain; | 
				
			||||
using ErsatzTV.Core.FFmpeg; | 
				
			||||
using ErsatzTV.Core.Health; | 
				
			||||
using ErsatzTV.Core.Health.Checks; | 
				
			||||
using ErsatzTV.Core.Interfaces.Repositories; | 
				
			||||
using LanguageExt; | 
				
			||||
using ErsatzTV.Infrastructure.Data; | 
				
			||||
using Microsoft.EntityFrameworkCore; | 
				
			||||
 | 
				
			||||
namespace ErsatzTV.Infrastructure.Health.Checks | 
				
			||||
{ | 
				
			||||
    public class VaapiDriverHealthCheck : BaseHealthCheck, IVaapiDriverHealthCheck | 
				
			||||
    { | 
				
			||||
        private readonly IConfigElementRepository _configElementRepository; | 
				
			||||
        private readonly IDbContextFactory<TvContext> _dbContextFactory; | 
				
			||||
 | 
				
			||||
        public VaapiDriverHealthCheck(IConfigElementRepository configElementRepository) => | 
				
			||||
            _configElementRepository = configElementRepository; | 
				
			||||
        public VaapiDriverHealthCheck(IDbContextFactory<TvContext> dbContextFactory) | 
				
			||||
        { | 
				
			||||
            _dbContextFactory = dbContextFactory; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        protected override string Title => "VAAPI Driver"; | 
				
			||||
 | 
				
			||||
        public async Task<HealthCheckResult> Check() | 
				
			||||
        { | 
				
			||||
            string version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>() | 
				
			||||
                ?.InformationalVersion ?? "unknown"; | 
				
			||||
 | 
				
			||||
            if (!version.Contains("docker", StringComparison.OrdinalIgnoreCase) || | 
				
			||||
                !version.Contains("vaapi", StringComparison.OrdinalIgnoreCase)) | 
				
			||||
            { | 
				
			||||
                return NotApplicableResult(); | 
				
			||||
            } | 
				
			||||
            await using TvContext dbContext = _dbContextFactory.CreateDbContext(); | 
				
			||||
            List<FFmpegProfile> profiles = await dbContext.FFmpegProfiles | 
				
			||||
                .Filter(p => p.HardwareAcceleration == HardwareAccelerationKind.Vaapi) | 
				
			||||
                .ToListAsync(); | 
				
			||||
             | 
				
			||||
            Option<int> maybeVaapiDriver = | 
				
			||||
                await _configElementRepository.GetValue<int>(ConfigElementKey.FFmpegVaapiDriver); | 
				
			||||
            var vaapiDriver = (VaapiDriver)await maybeVaapiDriver.IfNoneAsync(0); | 
				
			||||
            if (vaapiDriver == VaapiDriver.Default) | 
				
			||||
            if (profiles.Count == 0) | 
				
			||||
            { | 
				
			||||
                return InfoResult( | 
				
			||||
                    "Settings > FFmpeg Settings > VAAPI Driver is set to Default; selecting iHD (Gen 8+) or i965 (up to Gen 9) may offer better performance"); | 
				
			||||
                return NotApplicableResult(); | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            return OkResult(); | 
				
			||||
 | 
				
			||||
            var defaultProfiles = profiles | 
				
			||||
                .Filter(p => p.VaapiDriver == VaapiDriver.Default) | 
				
			||||
                .ToList(); | 
				
			||||
 | 
				
			||||
            return defaultProfiles.Any() | 
				
			||||
                ? InfoResult( | 
				
			||||
                    $"{defaultProfiles.Count} FFmpeg Profile{(defaultProfiles.Count > 1 ? "s are" : " is")} set to use Default VAAPI Driver; selecting iHD (Gen 8+) or i965 (up to Gen 9) may offer better performance with Intel iGPU") | 
				
			||||
                : OkResult(); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
				 
					 | 
				
			||||
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						@ -0,0 +1,34 @@
				@@ -0,0 +1,34 @@
					 | 
				
			||||
using Microsoft.EntityFrameworkCore.Migrations; | 
				
			||||
 | 
				
			||||
namespace ErsatzTV.Infrastructure.Migrations | 
				
			||||
{ | 
				
			||||
    public partial class Add_FFmpegProfileVaapiDriverVaapiDevice : Migration | 
				
			||||
    { | 
				
			||||
        protected override void Up(MigrationBuilder migrationBuilder) | 
				
			||||
        { | 
				
			||||
            migrationBuilder.AddColumn<string>( | 
				
			||||
                name: "VaapiDevice", | 
				
			||||
                table: "FFmpegProfile", | 
				
			||||
                type: "TEXT", | 
				
			||||
                nullable: true); | 
				
			||||
 | 
				
			||||
            migrationBuilder.AddColumn<int>( | 
				
			||||
                name: "VaapiDriver", | 
				
			||||
                table: "FFmpegProfile", | 
				
			||||
                type: "INTEGER", | 
				
			||||
                nullable: false, | 
				
			||||
                defaultValue: 0); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        protected override void Down(MigrationBuilder migrationBuilder) | 
				
			||||
        { | 
				
			||||
            migrationBuilder.DropColumn( | 
				
			||||
                name: "VaapiDevice", | 
				
			||||
                table: "FFmpegProfile"); | 
				
			||||
 | 
				
			||||
            migrationBuilder.DropColumn( | 
				
			||||
                name: "VaapiDriver", | 
				
			||||
                table: "FFmpegProfile"); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						@ -0,0 +1,19 @@
				@@ -0,0 +1,19 @@
					 | 
				
			||||
using Microsoft.EntityFrameworkCore.Migrations; | 
				
			||||
 | 
				
			||||
namespace ErsatzTV.Infrastructure.Migrations | 
				
			||||
{ | 
				
			||||
    public partial class Update_FFmpegProfileVaapiDriverVaapiDevice : Migration | 
				
			||||
    { | 
				
			||||
        protected override void Up(MigrationBuilder migrationBuilder) | 
				
			||||
        { | 
				
			||||
            migrationBuilder.Sql("UPDATE FFmpegProfile SET VaapiDevice = '/dev/dri/renderD128'"); | 
				
			||||
            migrationBuilder.Sql( | 
				
			||||
                "UPDATE FFmpegProfile SET VaapiDriver = (SELECT IFNULL(Value, 0) FROM ConfigElement WHERE Key = 'ffmpeg.vaapi_driver')"); | 
				
			||||
            migrationBuilder.Sql("DELETE FROM ConfigElement WHERE Key = 'ffmpeg.vaapi_driver'"); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        protected override void Down(MigrationBuilder migrationBuilder) | 
				
			||||
        { | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue