< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.Routines.FixNullEncoderPreset
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20260915104305_FixNullEncoderPreset.cs
Line coverage
92%
Covered lines: 23
Uncovered lines: 2
Coverable lines: 25
Total lines: 77
Line coverage: 92%
Branch coverage
71%
Covered branches: 10
Total branches: 14
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/29/2026 - 12:17:11 AM Line coverage: 92% (23/25) Branch coverage: 71.4% (10/14) Total lines: 77 10/29/2026 - 12:17:11 AM Line coverage: 92% (23/25) Branch coverage: 71.4% (10/14) Total lines: 77

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
PerformAsync(...)71.42%141490.47%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20260915104305_FixNullEncoderPreset.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using System.Xml;
 6using System.Xml.Linq;
 7using Jellyfin.Server.Migrations.Stages;
 8using MediaBrowser.Common.Configuration;
 9using MediaBrowser.Model.Configuration;
 10using MediaBrowser.Model.Entities;
 11using Microsoft.Extensions.Logging;
 12
 13namespace Jellyfin.Server.Migrations.Routines;
 14
 15/// <summary>
 16/// Replaces the nullable encoder preset written by older versions with the default preset.
 17/// </summary>
 18[JellyfinMigration("2026-09-15T10:43:05", nameof(FixNullEncoderPreset), Stage = JellyfinMigrationStageTypes.PreInitialis
 19internal class FixNullEncoderPreset : IAsyncMigrationRoutine
 20{
 121    private static readonly XNamespace _xsiNamespace = "http://www.w3.org/2001/XMLSchema-instance";
 22
 23    private readonly IApplicationPaths _applicationPaths;
 24    private readonly ILogger<FixNullEncoderPreset> _logger;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="FixNullEncoderPreset"/> class.
 28    /// </summary>
 29    /// <param name="applicationPaths">The application paths.</param>
 30    /// <param name="logger">The logger.</param>
 31    public FixNullEncoderPreset(IApplicationPaths applicationPaths, ILogger<FixNullEncoderPreset> logger)
 32    {
 433        _applicationPaths = applicationPaths;
 434        _logger = logger;
 435    }
 36
 37    /// <inheritdoc />
 38    public Task PerformAsync(CancellationToken cancellationToken)
 39    {
 340        cancellationToken.ThrowIfCancellationRequested();
 41
 342        var path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "encoding.xml");
 343        if (!File.Exists(path))
 44        {
 045            return Task.CompletedTask;
 46        }
 47
 48        XDocument document;
 49        try
 50        {
 351            document = XDocument.Load(path, LoadOptions.PreserveWhitespace);
 252        }
 153        catch (XmlException ex)
 54        {
 155            _logger.LogWarning(ex, "Could not parse encoding configuration; skipping null encoder preset migration");
 156            return Task.CompletedTask;
 57        }
 58
 259        var encoderPreset = document.Root?.Element(nameof(EncodingOptions.EncoderPreset));
 260        if (encoderPreset is null)
 61        {
 062            return Task.CompletedTask;
 63        }
 64
 265        var nilAttribute = encoderPreset.Attribute(_xsiNamespace + "nil");
 266        if (!string.Equals(nilAttribute?.Value, "true", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(enc
 67        {
 168            return Task.CompletedTask;
 69        }
 70
 171        nilAttribute?.Remove();
 172        encoderPreset.Value = nameof(EncoderPreset.auto);
 173        document.Save(path, SaveOptions.DisableFormatting);
 174        _logger.LogInformation("Replaced null encoder preset with auto in encoding configuration");
 175        return Task.CompletedTask;
 176    }
 77}