< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.PreStartupRoutines.MigrateEncodingOptions
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 87
Coverable lines: 87
Total lines: 239
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Perform()0%210140%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Xml;
 4using System.Xml.Serialization;
 5using Emby.Server.Implementations;
 6using MediaBrowser.Model.Configuration;
 7using MediaBrowser.Model.Entities;
 8using Microsoft.Extensions.Logging;
 9
 10namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 11
 12/// <inheritdoc />
 13#pragma warning disable CS0618 // Type or member is obsolete
 14[JellyfinMigration("2025-04-20T03:00:00", nameof(MigrateEncodingOptions), "A8E61960-7726-4450-8F3D-82C12DAABBCB", Stage 
 15public class MigrateEncodingOptions : IMigrationRoutine
 16#pragma warning restore CS0618 // Type or member is obsolete
 17{
 18    private readonly ServerApplicationPaths _applicationPaths;
 19    private readonly ILogger<MigrateEncodingOptions> _logger;
 20
 21    /// <summary>
 22    /// Initializes a new instance of the <see cref="MigrateEncodingOptions"/> class.
 23    /// </summary>
 24    /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
 25    /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
 26    public MigrateEncodingOptions(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
 27    {
 028        _applicationPaths = applicationPaths;
 029        _logger = loggerFactory.CreateLogger<MigrateEncodingOptions>();
 030    }
 31
 32    /// <inheritdoc />
 33    public void Perform()
 34    {
 035        string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "encoding.xml");
 036        var oldSerializer = new XmlSerializer(typeof(OldEncodingOptions), new XmlRootAttribute("EncodingOptions"));
 037        OldEncodingOptions? oldConfig = null;
 38
 39        try
 40        {
 041            using var xmlReader = XmlReader.Create(path);
 042            oldConfig = (OldEncodingOptions?)oldSerializer.Deserialize(xmlReader);
 043        }
 044        catch (InvalidOperationException ex)
 45        {
 046            _logger.LogError(ex, "Migrate EncodingOptions deserialize Invalid Operation error");
 047        }
 048        catch (Exception ex)
 49        {
 050            _logger.LogError(ex, "Migrate EncodingOptions deserialize error");
 051        }
 52
 053        if (oldConfig is null)
 54        {
 055            return;
 56        }
 57
 058        var hardwareAccelerationType = HardwareAccelerationType.none;
 059        if (Enum.TryParse<HardwareAccelerationType>(oldConfig.HardwareAccelerationType, true, out var parsedHardwareAcce
 60        {
 061            hardwareAccelerationType = parsedHardwareAccelerationType;
 62        }
 63
 064        var tonemappingAlgorithm = TonemappingAlgorithm.none;
 065        if (Enum.TryParse<TonemappingAlgorithm>(oldConfig.TonemappingAlgorithm, true, out var parsedTonemappingAlgorithm
 66        {
 067            tonemappingAlgorithm = parsedTonemappingAlgorithm;
 68        }
 69
 070        var tonemappingMode = TonemappingMode.auto;
 071        if (Enum.TryParse<TonemappingMode>(oldConfig.TonemappingMode, true, out var parsedTonemappingMode))
 72        {
 073            tonemappingMode = parsedTonemappingMode;
 74        }
 75
 076        var tonemappingRange = TonemappingRange.auto;
 077        if (Enum.TryParse<TonemappingRange>(oldConfig.TonemappingRange, true, out var parsedTonemappingRange))
 78        {
 079            tonemappingRange = parsedTonemappingRange;
 80        }
 81
 082        var encoderPreset = EncoderPreset.superfast;
 083        if (Enum.TryParse<EncoderPreset>(oldConfig.TonemappingRange, true, out var parsedEncoderPreset))
 84        {
 085            encoderPreset = parsedEncoderPreset;
 86        }
 87
 088        var deinterlaceMethod = DeinterlaceMethod.yadif;
 089        if (Enum.TryParse<DeinterlaceMethod>(oldConfig.TonemappingRange, true, out var parsedDeinterlaceMethod))
 90        {
 091            deinterlaceMethod = parsedDeinterlaceMethod;
 92        }
 93
 094        var encodingOptions = new EncodingOptions()
 095        {
 096            EncodingThreadCount = oldConfig.EncodingThreadCount,
 097            TranscodingTempPath = oldConfig.TranscodingTempPath,
 098            FallbackFontPath = oldConfig.FallbackFontPath,
 099            EnableFallbackFont = oldConfig.EnableFallbackFont,
 0100            EnableAudioVbr = oldConfig.EnableAudioVbr,
 0101            DownMixAudioBoost = oldConfig.DownMixAudioBoost,
 0102            DownMixStereoAlgorithm = oldConfig.DownMixStereoAlgorithm,
 0103            MaxMuxingQueueSize = oldConfig.MaxMuxingQueueSize,
 0104            EnableThrottling = oldConfig.EnableThrottling,
 0105            ThrottleDelaySeconds = oldConfig.ThrottleDelaySeconds,
 0106            EnableSegmentDeletion = oldConfig.EnableSegmentDeletion,
 0107            SegmentKeepSeconds = oldConfig.SegmentKeepSeconds,
 0108            HardwareAccelerationType = hardwareAccelerationType,
 0109            EncoderAppPath = oldConfig.EncoderAppPath,
 0110            EncoderAppPathDisplay = oldConfig.EncoderAppPathDisplay,
 0111            VaapiDevice = oldConfig.VaapiDevice,
 0112            EnableTonemapping = oldConfig.EnableTonemapping,
 0113            EnableVppTonemapping = oldConfig.EnableVppTonemapping,
 0114            EnableVideoToolboxTonemapping = oldConfig.EnableVideoToolboxTonemapping,
 0115            TonemappingAlgorithm = tonemappingAlgorithm,
 0116            TonemappingMode = tonemappingMode,
 0117            TonemappingRange = tonemappingRange,
 0118            TonemappingDesat = oldConfig.TonemappingDesat,
 0119            TonemappingPeak = oldConfig.TonemappingPeak,
 0120            TonemappingParam = oldConfig.TonemappingParam,
 0121            VppTonemappingBrightness = oldConfig.VppTonemappingBrightness,
 0122            VppTonemappingContrast = oldConfig.VppTonemappingContrast,
 0123            H264Crf = oldConfig.H264Crf,
 0124            H265Crf = oldConfig.H265Crf,
 0125            EncoderPreset = encoderPreset,
 0126            DeinterlaceDoubleRate = oldConfig.DeinterlaceDoubleRate,
 0127            DeinterlaceMethod = deinterlaceMethod,
 0128            EnableDecodingColorDepth10Hevc = oldConfig.EnableDecodingColorDepth10Hevc,
 0129            EnableDecodingColorDepth10Vp9 = oldConfig.EnableDecodingColorDepth10Vp9,
 0130            EnableEnhancedNvdecDecoder = oldConfig.EnableEnhancedNvdecDecoder,
 0131            PreferSystemNativeHwDecoder = oldConfig.PreferSystemNativeHwDecoder,
 0132            EnableIntelLowPowerH264HwEncoder = oldConfig.EnableIntelLowPowerH264HwEncoder,
 0133            EnableIntelLowPowerHevcHwEncoder = oldConfig.EnableIntelLowPowerHevcHwEncoder,
 0134            EnableHardwareEncoding = oldConfig.EnableHardwareEncoding,
 0135            AllowHevcEncoding = oldConfig.AllowHevcEncoding,
 0136            AllowAv1Encoding = oldConfig.AllowAv1Encoding,
 0137            EnableSubtitleExtraction = oldConfig.EnableSubtitleExtraction,
 0138            HardwareDecodingCodecs = oldConfig.HardwareDecodingCodecs,
 0139            AllowOnDemandMetadataBasedKeyframeExtractionForExtensions = oldConfig.AllowOnDemandMetadataBasedKeyframeExtr
 0140        };
 141
 0142        var newSerializer = new XmlSerializer(typeof(EncodingOptions));
 0143        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 0144        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 0145        newSerializer.Serialize(xmlWriter, encodingOptions);
 0146    }
 147
 148#pragma warning disable
 149    public sealed class OldEncodingOptions
 150    {
 151        public int EncodingThreadCount { get; set; }
 152
 153        public string TranscodingTempPath { get; set; }
 154
 155        public string FallbackFontPath { get; set; }
 156
 157        public bool EnableFallbackFont { get; set; }
 158
 159        public bool EnableAudioVbr { get; set; }
 160
 161        public double DownMixAudioBoost { get; set; }
 162
 163        public DownMixStereoAlgorithms DownMixStereoAlgorithm { get; set; }
 164
 165        public int MaxMuxingQueueSize { get; set; }
 166
 167        public bool EnableThrottling { get; set; }
 168
 169        public int ThrottleDelaySeconds { get; set; }
 170
 171        public bool EnableSegmentDeletion { get; set; }
 172
 173        public int SegmentKeepSeconds { get; set; }
 174
 175        public string HardwareAccelerationType { get; set; }
 176
 177        public string EncoderAppPath { get; set; }
 178
 179        public string EncoderAppPathDisplay { get; set; }
 180
 181        public string VaapiDevice { get; set; }
 182
 183        public bool EnableTonemapping { get; set; }
 184
 185        public bool EnableVppTonemapping { get; set; }
 186
 187        public bool EnableVideoToolboxTonemapping { get; set; }
 188
 189        public string TonemappingAlgorithm { get; set; }
 190
 191        public string TonemappingMode { get; set; }
 192
 193        public string TonemappingRange { get; set; }
 194
 195        public double TonemappingDesat { get; set; }
 196
 197        public double TonemappingPeak { get; set; }
 198
 199        public double TonemappingParam { get; set; }
 200
 201        public double VppTonemappingBrightness { get; set; }
 202
 203        public double VppTonemappingContrast { get; set; }
 204
 205        public int H264Crf { get; set; }
 206
 207        public int H265Crf { get; set; }
 208
 209        public string EncoderPreset { get; set; }
 210
 211        public bool DeinterlaceDoubleRate { get; set; }
 212
 213        public string DeinterlaceMethod { get; set; }
 214
 215        public bool EnableDecodingColorDepth10Hevc { get; set; }
 216
 217        public bool EnableDecodingColorDepth10Vp9 { get; set; }
 218
 219        public bool EnableEnhancedNvdecDecoder { get; set; }
 220
 221        public bool PreferSystemNativeHwDecoder { get; set; }
 222
 223        public bool EnableIntelLowPowerH264HwEncoder { get; set; }
 224
 225        public bool EnableIntelLowPowerHevcHwEncoder { get; set; }
 226
 227        public bool EnableHardwareEncoding { get; set; }
 228
 229        public bool AllowHevcEncoding { get; set; }
 230
 231        public bool AllowAv1Encoding { get; set; }
 232
 233        public bool EnableSubtitleExtraction { get; set; }
 234
 235        public string[] HardwareDecodingCodecs { get; set; }
 236
 237        public string[] AllowOnDemandMetadataBasedKeyframeExtractionForExtensions { get; set; }
 238    }
 239}