| | | 1 | | using System; |
| | | 2 | | using System.IO; |
| | | 3 | | using System.Xml; |
| | | 4 | | using System.Xml.Serialization; |
| | | 5 | | using Emby.Server.Implementations; |
| | | 6 | | using MediaBrowser.Model.Configuration; |
| | | 7 | | using MediaBrowser.Model.Entities; |
| | | 8 | | using Microsoft.Extensions.Logging; |
| | | 9 | | |
| | | 10 | | namespace 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 |
| | | 15 | | public 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 | | { |
| | 0 | 28 | | _applicationPaths = applicationPaths; |
| | 0 | 29 | | _logger = loggerFactory.CreateLogger<MigrateEncodingOptions>(); |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | | 33 | | public void Perform() |
| | | 34 | | { |
| | 0 | 35 | | string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "encoding.xml"); |
| | 0 | 36 | | var oldSerializer = new XmlSerializer(typeof(OldEncodingOptions), new XmlRootAttribute("EncodingOptions")); |
| | 0 | 37 | | OldEncodingOptions? oldConfig = null; |
| | | 38 | | |
| | | 39 | | try |
| | | 40 | | { |
| | 0 | 41 | | using var xmlReader = XmlReader.Create(path); |
| | 0 | 42 | | oldConfig = (OldEncodingOptions?)oldSerializer.Deserialize(xmlReader); |
| | 0 | 43 | | } |
| | 0 | 44 | | catch (InvalidOperationException ex) |
| | | 45 | | { |
| | 0 | 46 | | _logger.LogError(ex, "Migrate EncodingOptions deserialize Invalid Operation error"); |
| | 0 | 47 | | } |
| | 0 | 48 | | catch (Exception ex) |
| | | 49 | | { |
| | 0 | 50 | | _logger.LogError(ex, "Migrate EncodingOptions deserialize error"); |
| | 0 | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | if (oldConfig is null) |
| | | 54 | | { |
| | 0 | 55 | | return; |
| | | 56 | | } |
| | | 57 | | |
| | 0 | 58 | | var hardwareAccelerationType = HardwareAccelerationType.none; |
| | 0 | 59 | | if (Enum.TryParse<HardwareAccelerationType>(oldConfig.HardwareAccelerationType, true, out var parsedHardwareAcce |
| | | 60 | | { |
| | 0 | 61 | | hardwareAccelerationType = parsedHardwareAccelerationType; |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | var tonemappingAlgorithm = TonemappingAlgorithm.none; |
| | 0 | 65 | | if (Enum.TryParse<TonemappingAlgorithm>(oldConfig.TonemappingAlgorithm, true, out var parsedTonemappingAlgorithm |
| | | 66 | | { |
| | 0 | 67 | | tonemappingAlgorithm = parsedTonemappingAlgorithm; |
| | | 68 | | } |
| | | 69 | | |
| | 0 | 70 | | var tonemappingMode = TonemappingMode.auto; |
| | 0 | 71 | | if (Enum.TryParse<TonemappingMode>(oldConfig.TonemappingMode, true, out var parsedTonemappingMode)) |
| | | 72 | | { |
| | 0 | 73 | | tonemappingMode = parsedTonemappingMode; |
| | | 74 | | } |
| | | 75 | | |
| | 0 | 76 | | var tonemappingRange = TonemappingRange.auto; |
| | 0 | 77 | | if (Enum.TryParse<TonemappingRange>(oldConfig.TonemappingRange, true, out var parsedTonemappingRange)) |
| | | 78 | | { |
| | 0 | 79 | | tonemappingRange = parsedTonemappingRange; |
| | | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | var encoderPreset = EncoderPreset.superfast; |
| | 0 | 83 | | if (Enum.TryParse<EncoderPreset>(oldConfig.TonemappingRange, true, out var parsedEncoderPreset)) |
| | | 84 | | { |
| | 0 | 85 | | encoderPreset = parsedEncoderPreset; |
| | | 86 | | } |
| | | 87 | | |
| | 0 | 88 | | var deinterlaceMethod = DeinterlaceMethod.yadif; |
| | 0 | 89 | | if (Enum.TryParse<DeinterlaceMethod>(oldConfig.TonemappingRange, true, out var parsedDeinterlaceMethod)) |
| | | 90 | | { |
| | 0 | 91 | | deinterlaceMethod = parsedDeinterlaceMethod; |
| | | 92 | | } |
| | | 93 | | |
| | 0 | 94 | | var encodingOptions = new EncodingOptions() |
| | 0 | 95 | | { |
| | 0 | 96 | | EncodingThreadCount = oldConfig.EncodingThreadCount, |
| | 0 | 97 | | TranscodingTempPath = oldConfig.TranscodingTempPath, |
| | 0 | 98 | | FallbackFontPath = oldConfig.FallbackFontPath, |
| | 0 | 99 | | EnableFallbackFont = oldConfig.EnableFallbackFont, |
| | 0 | 100 | | EnableAudioVbr = oldConfig.EnableAudioVbr, |
| | 0 | 101 | | DownMixAudioBoost = oldConfig.DownMixAudioBoost, |
| | 0 | 102 | | DownMixStereoAlgorithm = oldConfig.DownMixStereoAlgorithm, |
| | 0 | 103 | | MaxMuxingQueueSize = oldConfig.MaxMuxingQueueSize, |
| | 0 | 104 | | EnableThrottling = oldConfig.EnableThrottling, |
| | 0 | 105 | | ThrottleDelaySeconds = oldConfig.ThrottleDelaySeconds, |
| | 0 | 106 | | EnableSegmentDeletion = oldConfig.EnableSegmentDeletion, |
| | 0 | 107 | | SegmentKeepSeconds = oldConfig.SegmentKeepSeconds, |
| | 0 | 108 | | HardwareAccelerationType = hardwareAccelerationType, |
| | 0 | 109 | | EncoderAppPath = oldConfig.EncoderAppPath, |
| | 0 | 110 | | EncoderAppPathDisplay = oldConfig.EncoderAppPathDisplay, |
| | 0 | 111 | | VaapiDevice = oldConfig.VaapiDevice, |
| | 0 | 112 | | EnableTonemapping = oldConfig.EnableTonemapping, |
| | 0 | 113 | | EnableVppTonemapping = oldConfig.EnableVppTonemapping, |
| | 0 | 114 | | EnableVideoToolboxTonemapping = oldConfig.EnableVideoToolboxTonemapping, |
| | 0 | 115 | | TonemappingAlgorithm = tonemappingAlgorithm, |
| | 0 | 116 | | TonemappingMode = tonemappingMode, |
| | 0 | 117 | | TonemappingRange = tonemappingRange, |
| | 0 | 118 | | TonemappingDesat = oldConfig.TonemappingDesat, |
| | 0 | 119 | | TonemappingPeak = oldConfig.TonemappingPeak, |
| | 0 | 120 | | TonemappingParam = oldConfig.TonemappingParam, |
| | 0 | 121 | | VppTonemappingBrightness = oldConfig.VppTonemappingBrightness, |
| | 0 | 122 | | VppTonemappingContrast = oldConfig.VppTonemappingContrast, |
| | 0 | 123 | | H264Crf = oldConfig.H264Crf, |
| | 0 | 124 | | H265Crf = oldConfig.H265Crf, |
| | 0 | 125 | | EncoderPreset = encoderPreset, |
| | 0 | 126 | | DeinterlaceDoubleRate = oldConfig.DeinterlaceDoubleRate, |
| | 0 | 127 | | DeinterlaceMethod = deinterlaceMethod, |
| | 0 | 128 | | EnableDecodingColorDepth10Hevc = oldConfig.EnableDecodingColorDepth10Hevc, |
| | 0 | 129 | | EnableDecodingColorDepth10Vp9 = oldConfig.EnableDecodingColorDepth10Vp9, |
| | 0 | 130 | | EnableEnhancedNvdecDecoder = oldConfig.EnableEnhancedNvdecDecoder, |
| | 0 | 131 | | PreferSystemNativeHwDecoder = oldConfig.PreferSystemNativeHwDecoder, |
| | 0 | 132 | | EnableIntelLowPowerH264HwEncoder = oldConfig.EnableIntelLowPowerH264HwEncoder, |
| | 0 | 133 | | EnableIntelLowPowerHevcHwEncoder = oldConfig.EnableIntelLowPowerHevcHwEncoder, |
| | 0 | 134 | | EnableHardwareEncoding = oldConfig.EnableHardwareEncoding, |
| | 0 | 135 | | AllowHevcEncoding = oldConfig.AllowHevcEncoding, |
| | 0 | 136 | | AllowAv1Encoding = oldConfig.AllowAv1Encoding, |
| | 0 | 137 | | EnableSubtitleExtraction = oldConfig.EnableSubtitleExtraction, |
| | 0 | 138 | | HardwareDecodingCodecs = oldConfig.HardwareDecodingCodecs, |
| | 0 | 139 | | AllowOnDemandMetadataBasedKeyframeExtractionForExtensions = oldConfig.AllowOnDemandMetadataBasedKeyframeExtr |
| | 0 | 140 | | }; |
| | | 141 | | |
| | 0 | 142 | | var newSerializer = new XmlSerializer(typeof(EncodingOptions)); |
| | 0 | 143 | | var xmlWriterSettings = new XmlWriterSettings { Indent = true }; |
| | 0 | 144 | | using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings); |
| | 0 | 145 | | newSerializer.Serialize(xmlWriter, encodingOptions); |
| | 0 | 146 | | } |
| | | 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 | | } |