aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/PreStartupRoutines
diff options
context:
space:
mode:
authorTim Eisele <Shadowghost@users.noreply.github.com>2024-09-09 16:43:37 +0200
committerGitHub <noreply@github.com>2024-09-09 08:43:37 -0600
commit0d85af019c6ebc855ab2d8e689abe72b995225b4 (patch)
tree466daf3cd9b8f37307b4104cd272afc9806d92c6 /Jellyfin.Server/Migrations/PreStartupRoutines
parent54f663b0f3c4a9cc5a4f44d1afcb6e1de03c0503 (diff)
Use enums for encoding options (#12561)
Diffstat (limited to 'Jellyfin.Server/Migrations/PreStartupRoutines')
-rw-r--r--Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs1
-rw-r--r--Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs245
-rw-r--r--Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs10
-rw-r--r--Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs85
4 files changed, 294 insertions, 47 deletions
diff --git a/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs b/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs
index 139a6ec640..8462d0a8c9 100644
--- a/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs
+++ b/Jellyfin.Server/Migrations/PreStartupRoutines/CreateNetworkConfiguration.cs
@@ -132,5 +132,4 @@ public class CreateNetworkConfiguration : IMigrationRoutine
public string[] KnownProxies { get; set; } = Array.Empty<string>();
}
-#pragma warning restore
}
diff --git a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs
new file mode 100644
index 0000000000..61f5620dc0
--- /dev/null
+++ b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateEncodingOptions.cs
@@ -0,0 +1,245 @@
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+using Emby.Server.Implementations;
+using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Entities;
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Server.Migrations.PreStartupRoutines;
+
+/// <inheritdoc />
+public class MigrateEncodingOptions : IMigrationRoutine
+{
+ private readonly ServerApplicationPaths _applicationPaths;
+ private readonly ILogger<MigrateEncodingOptions> _logger;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MigrateEncodingOptions"/> class.
+ /// </summary>
+ /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
+ /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
+ public MigrateEncodingOptions(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
+ {
+ _applicationPaths = applicationPaths;
+ _logger = loggerFactory.CreateLogger<MigrateEncodingOptions>();
+ }
+
+ /// <inheritdoc />
+ public Guid Id => Guid.Parse("A8E61960-7726-4450-8F3D-82C12DAABBCB");
+
+ /// <inheritdoc />
+ public string Name => nameof(MigrateEncodingOptions);
+
+ /// <inheritdoc />
+ public bool PerformOnNewInstall => false;
+
+ /// <inheritdoc />
+ public void Perform()
+ {
+ string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "encoding.xml");
+ var oldSerializer = new XmlSerializer(typeof(OldEncodingOptions), new XmlRootAttribute("EncodingOptions"));
+ OldEncodingOptions? oldConfig = null;
+
+ try
+ {
+ using var xmlReader = XmlReader.Create(path);
+ oldConfig = (OldEncodingOptions?)oldSerializer.Deserialize(xmlReader);
+ }
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogError(ex, "Migrate EncodingOptions deserialize Invalid Operation error");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Migrate EncodingOptions deserialize error");
+ }
+
+ if (oldConfig is null)
+ {
+ return;
+ }
+
+ var hardwareAccelerationType = HardwareAccelerationType.none;
+ if (Enum.TryParse<HardwareAccelerationType>(oldConfig.HardwareAccelerationType, true, out var parsedHardwareAccelerationType))
+ {
+ hardwareAccelerationType = parsedHardwareAccelerationType;
+ }
+
+ var tonemappingAlgorithm = TonemappingAlgorithm.none;
+ if (Enum.TryParse<TonemappingAlgorithm>(oldConfig.TonemappingAlgorithm, true, out var parsedTonemappingAlgorithm))
+ {
+ tonemappingAlgorithm = parsedTonemappingAlgorithm;
+ }
+
+ var tonemappingMode = TonemappingMode.auto;
+ if (Enum.TryParse<TonemappingMode>(oldConfig.TonemappingMode, true, out var parsedTonemappingMode))
+ {
+ tonemappingMode = parsedTonemappingMode;
+ }
+
+ var tonemappingRange = TonemappingRange.auto;
+ if (Enum.TryParse<TonemappingRange>(oldConfig.TonemappingRange, true, out var parsedTonemappingRange))
+ {
+ tonemappingRange = parsedTonemappingRange;
+ }
+
+ var encoderPreset = EncoderPreset.superfast;
+ if (Enum.TryParse<EncoderPreset>(oldConfig.TonemappingRange, true, out var parsedEncoderPreset))
+ {
+ encoderPreset = parsedEncoderPreset;
+ }
+
+ var deinterlaceMethod = DeinterlaceMethod.yadif;
+ if (Enum.TryParse<DeinterlaceMethod>(oldConfig.TonemappingRange, true, out var parsedDeinterlaceMethod))
+ {
+ deinterlaceMethod = parsedDeinterlaceMethod;
+ }
+
+ var encodingOptions = new EncodingOptions()
+ {
+ EncodingThreadCount = oldConfig.EncodingThreadCount,
+ TranscodingTempPath = oldConfig.TranscodingTempPath,
+ FallbackFontPath = oldConfig.FallbackFontPath,
+ EnableFallbackFont = oldConfig.EnableFallbackFont,
+ EnableAudioVbr = oldConfig.EnableAudioVbr,
+ DownMixAudioBoost = oldConfig.DownMixAudioBoost,
+ DownMixStereoAlgorithm = oldConfig.DownMixStereoAlgorithm,
+ MaxMuxingQueueSize = oldConfig.MaxMuxingQueueSize,
+ EnableThrottling = oldConfig.EnableThrottling,
+ ThrottleDelaySeconds = oldConfig.ThrottleDelaySeconds,
+ EnableSegmentDeletion = oldConfig.EnableSegmentDeletion,
+ SegmentKeepSeconds = oldConfig.SegmentKeepSeconds,
+ HardwareAccelerationType = hardwareAccelerationType,
+ EncoderAppPath = oldConfig.EncoderAppPath,
+ EncoderAppPathDisplay = oldConfig.EncoderAppPathDisplay,
+ VaapiDevice = oldConfig.VaapiDevice,
+ EnableTonemapping = oldConfig.EnableTonemapping,
+ EnableVppTonemapping = oldConfig.EnableVppTonemapping,
+ EnableVideoToolboxTonemapping = oldConfig.EnableVideoToolboxTonemapping,
+ TonemappingAlgorithm = tonemappingAlgorithm,
+ TonemappingMode = tonemappingMode,
+ TonemappingRange = tonemappingRange,
+ TonemappingDesat = oldConfig.TonemappingDesat,
+ TonemappingPeak = oldConfig.TonemappingPeak,
+ TonemappingParam = oldConfig.TonemappingParam,
+ VppTonemappingBrightness = oldConfig.VppTonemappingBrightness,
+ VppTonemappingContrast = oldConfig.VppTonemappingContrast,
+ H264Crf = oldConfig.H264Crf,
+ H265Crf = oldConfig.H265Crf,
+ EncoderPreset = encoderPreset,
+ DeinterlaceDoubleRate = oldConfig.DeinterlaceDoubleRate,
+ DeinterlaceMethod = deinterlaceMethod,
+ EnableDecodingColorDepth10Hevc = oldConfig.EnableDecodingColorDepth10Hevc,
+ EnableDecodingColorDepth10Vp9 = oldConfig.EnableDecodingColorDepth10Vp9,
+ EnableEnhancedNvdecDecoder = oldConfig.EnableEnhancedNvdecDecoder,
+ PreferSystemNativeHwDecoder = oldConfig.PreferSystemNativeHwDecoder,
+ EnableIntelLowPowerH264HwEncoder = oldConfig.EnableIntelLowPowerH264HwEncoder,
+ EnableIntelLowPowerHevcHwEncoder = oldConfig.EnableIntelLowPowerHevcHwEncoder,
+ EnableHardwareEncoding = oldConfig.EnableHardwareEncoding,
+ AllowHevcEncoding = oldConfig.AllowHevcEncoding,
+ AllowAv1Encoding = oldConfig.AllowAv1Encoding,
+ EnableSubtitleExtraction = oldConfig.EnableSubtitleExtraction,
+ HardwareDecodingCodecs = oldConfig.HardwareDecodingCodecs,
+ AllowOnDemandMetadataBasedKeyframeExtractionForExtensions = oldConfig.AllowOnDemandMetadataBasedKeyframeExtractionForExtensions
+ };
+
+ var newSerializer = new XmlSerializer(typeof(EncodingOptions));
+ var xmlWriterSettings = new XmlWriterSettings { Indent = true };
+ using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
+ newSerializer.Serialize(xmlWriter, encodingOptions);
+ }
+
+#pragma warning disable
+ public sealed class OldEncodingOptions
+ {
+ public int EncodingThreadCount { get; set; }
+
+ public string TranscodingTempPath { get; set; }
+
+ public string FallbackFontPath { get; set; }
+
+ public bool EnableFallbackFont { get; set; }
+
+ public bool EnableAudioVbr { get; set; }
+
+ public double DownMixAudioBoost { get; set; }
+
+ public DownMixStereoAlgorithms DownMixStereoAlgorithm { get; set; }
+
+ public int MaxMuxingQueueSize { get; set; }
+
+ public bool EnableThrottling { get; set; }
+
+ public int ThrottleDelaySeconds { get; set; }
+
+ public bool EnableSegmentDeletion { get; set; }
+
+ public int SegmentKeepSeconds { get; set; }
+
+ public string HardwareAccelerationType { get; set; }
+
+ public string EncoderAppPath { get; set; }
+
+ public string EncoderAppPathDisplay { get; set; }
+
+ public string VaapiDevice { get; set; }
+
+ public bool EnableTonemapping { get; set; }
+
+ public bool EnableVppTonemapping { get; set; }
+
+ public bool EnableVideoToolboxTonemapping { get; set; }
+
+ public string TonemappingAlgorithm { get; set; }
+
+ public string TonemappingMode { get; set; }
+
+ public string TonemappingRange { get; set; }
+
+ public double TonemappingDesat { get; set; }
+
+ public double TonemappingPeak { get; set; }
+
+ public double TonemappingParam { get; set; }
+
+ public double VppTonemappingBrightness { get; set; }
+
+ public double VppTonemappingContrast { get; set; }
+
+ public int H264Crf { get; set; }
+
+ public int H265Crf { get; set; }
+
+ public string EncoderPreset { get; set; }
+
+ public bool DeinterlaceDoubleRate { get; set; }
+
+ public string DeinterlaceMethod { get; set; }
+
+ public bool EnableDecodingColorDepth10Hevc { get; set; }
+
+ public bool EnableDecodingColorDepth10Vp9 { get; set; }
+
+ public bool EnableEnhancedNvdecDecoder { get; set; }
+
+ public bool PreferSystemNativeHwDecoder { get; set; }
+
+ public bool EnableIntelLowPowerH264HwEncoder { get; set; }
+
+ public bool EnableIntelLowPowerHevcHwEncoder { get; set; }
+
+ public bool EnableHardwareEncoding { get; set; }
+
+ public bool AllowHevcEncoding { get; set; }
+
+ public bool AllowAv1Encoding { get; set; }
+
+ public bool EnableSubtitleExtraction { get; set; }
+
+ public string[] HardwareDecodingCodecs { get; set; }
+
+ public string[] AllowOnDemandMetadataBasedKeyframeExtractionForExtensions { get; set; }
+ }
+}
diff --git a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs
index 0544fe561a..580282a5f5 100644
--- a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs
+++ b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs
@@ -48,9 +48,11 @@ public class MigrateMusicBrainzTimeout : IMigrationRoutine
if (oldPluginConfiguration is not null)
{
- var newPluginConfiguration = new PluginConfiguration();
- newPluginConfiguration.Server = oldPluginConfiguration.Server;
- newPluginConfiguration.ReplaceArtistName = oldPluginConfiguration.ReplaceArtistName;
+ var newPluginConfiguration = new PluginConfiguration
+ {
+ Server = oldPluginConfiguration.Server,
+ ReplaceArtistName = oldPluginConfiguration.ReplaceArtistName
+ };
var newRateLimit = oldPluginConfiguration.RateLimit / 1000.0;
newPluginConfiguration.RateLimit = newRateLimit < 1.0 ? 1.0 : newRateLimit;
WriteNew(path, newPluginConfiguration);
@@ -93,6 +95,4 @@ public class MigrateMusicBrainzTimeout : IMigrationRoutine
public bool ReplaceArtistName { get; set; }
}
-#pragma warning restore
-
}
diff --git a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs
index d92c00991b..49960f4305 100644
--- a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs
+++ b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateNetworkConfiguration.cs
@@ -55,49 +55,53 @@ public class MigrateNetworkConfiguration : IMigrationRoutine
_logger.LogError(ex, "Migrate NetworkConfiguration deserialize error");
}
- if (oldNetworkConfiguration is not null)
+ if (oldNetworkConfiguration is null)
{
- // Migrate network config values to new config schema
- var networkConfiguration = new NetworkConfiguration();
- networkConfiguration.AutoDiscovery = oldNetworkConfiguration.AutoDiscovery;
- networkConfiguration.BaseUrl = oldNetworkConfiguration.BaseUrl;
- networkConfiguration.CertificatePassword = oldNetworkConfiguration.CertificatePassword;
- networkConfiguration.CertificatePath = oldNetworkConfiguration.CertificatePath;
- networkConfiguration.EnableHttps = oldNetworkConfiguration.EnableHttps;
- networkConfiguration.EnableIPv4 = oldNetworkConfiguration.EnableIPV4;
- networkConfiguration.EnableIPv6 = oldNetworkConfiguration.EnableIPV6;
- networkConfiguration.EnablePublishedServerUriByRequest = oldNetworkConfiguration.EnablePublishedServerUriByRequest;
- networkConfiguration.EnableRemoteAccess = oldNetworkConfiguration.EnableRemoteAccess;
- networkConfiguration.EnableUPnP = oldNetworkConfiguration.EnableUPnP;
- networkConfiguration.IgnoreVirtualInterfaces = oldNetworkConfiguration.IgnoreVirtualInterfaces;
- networkConfiguration.InternalHttpPort = oldNetworkConfiguration.HttpServerPortNumber;
- networkConfiguration.InternalHttpsPort = oldNetworkConfiguration.HttpsPortNumber;
- networkConfiguration.IsRemoteIPFilterBlacklist = oldNetworkConfiguration.IsRemoteIPFilterBlacklist;
- networkConfiguration.KnownProxies = oldNetworkConfiguration.KnownProxies;
- networkConfiguration.LocalNetworkAddresses = oldNetworkConfiguration.LocalNetworkAddresses;
- networkConfiguration.LocalNetworkSubnets = oldNetworkConfiguration.LocalNetworkSubnets;
- networkConfiguration.PublicHttpPort = oldNetworkConfiguration.PublicPort;
- networkConfiguration.PublicHttpsPort = oldNetworkConfiguration.PublicHttpsPort;
- networkConfiguration.PublishedServerUriBySubnet = oldNetworkConfiguration.PublishedServerUriBySubnet;
- networkConfiguration.RemoteIPFilter = oldNetworkConfiguration.RemoteIPFilter;
- networkConfiguration.RequireHttps = oldNetworkConfiguration.RequireHttps;
-
- // Migrate old virtual interface name schema
- var oldVirtualInterfaceNames = oldNetworkConfiguration.VirtualInterfaceNames;
- if (oldVirtualInterfaceNames.Equals("vEthernet*", StringComparison.OrdinalIgnoreCase))
- {
- networkConfiguration.VirtualInterfaceNames = new string[] { "veth" };
- }
- else
- {
- networkConfiguration.VirtualInterfaceNames = oldVirtualInterfaceNames.Replace("*", string.Empty, StringComparison.OrdinalIgnoreCase).Split(',');
- }
+ return;
+ }
- var networkConfigSerializer = new XmlSerializer(typeof(NetworkConfiguration));
- var xmlWriterSettings = new XmlWriterSettings { Indent = true };
- using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
- networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
+ // Migrate network config values to new config schema
+ var networkConfiguration = new NetworkConfiguration
+ {
+ AutoDiscovery = oldNetworkConfiguration.AutoDiscovery,
+ BaseUrl = oldNetworkConfiguration.BaseUrl,
+ CertificatePassword = oldNetworkConfiguration.CertificatePassword,
+ CertificatePath = oldNetworkConfiguration.CertificatePath,
+ EnableHttps = oldNetworkConfiguration.EnableHttps,
+ EnableIPv4 = oldNetworkConfiguration.EnableIPV4,
+ EnableIPv6 = oldNetworkConfiguration.EnableIPV6,
+ EnablePublishedServerUriByRequest = oldNetworkConfiguration.EnablePublishedServerUriByRequest,
+ EnableRemoteAccess = oldNetworkConfiguration.EnableRemoteAccess,
+ EnableUPnP = oldNetworkConfiguration.EnableUPnP,
+ IgnoreVirtualInterfaces = oldNetworkConfiguration.IgnoreVirtualInterfaces,
+ InternalHttpPort = oldNetworkConfiguration.HttpServerPortNumber,
+ InternalHttpsPort = oldNetworkConfiguration.HttpsPortNumber,
+ IsRemoteIPFilterBlacklist = oldNetworkConfiguration.IsRemoteIPFilterBlacklist,
+ KnownProxies = oldNetworkConfiguration.KnownProxies,
+ LocalNetworkAddresses = oldNetworkConfiguration.LocalNetworkAddresses,
+ LocalNetworkSubnets = oldNetworkConfiguration.LocalNetworkSubnets,
+ PublicHttpPort = oldNetworkConfiguration.PublicPort,
+ PublicHttpsPort = oldNetworkConfiguration.PublicHttpsPort,
+ PublishedServerUriBySubnet = oldNetworkConfiguration.PublishedServerUriBySubnet,
+ RemoteIPFilter = oldNetworkConfiguration.RemoteIPFilter,
+ RequireHttps = oldNetworkConfiguration.RequireHttps
+ };
+
+ // Migrate old virtual interface name schema
+ var oldVirtualInterfaceNames = oldNetworkConfiguration.VirtualInterfaceNames;
+ if (oldVirtualInterfaceNames.Equals("vEthernet*", StringComparison.OrdinalIgnoreCase))
+ {
+ networkConfiguration.VirtualInterfaceNames = new string[] { "veth" };
}
+ else
+ {
+ networkConfiguration.VirtualInterfaceNames = oldVirtualInterfaceNames.Replace("*", string.Empty, StringComparison.OrdinalIgnoreCase).Split(',');
+ }
+
+ var networkConfigSerializer = new XmlSerializer(typeof(NetworkConfiguration));
+ var xmlWriterSettings = new XmlWriterSettings { Indent = true };
+ using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
+ networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
}
#pragma warning disable
@@ -204,5 +208,4 @@ public class MigrateNetworkConfiguration : IMigrationRoutine
public bool EnablePublishedServerUriByRequest { get; set; } = false;
}
-#pragma warning restore
}