瀏覽代碼

Use nullable enum type instead of strings

Brandon Nguyen 3 年之前
父節點
當前提交
d0c5e25ec0

+ 7 - 5
Jellyfin.Api/Helpers/TranscodingJobHelper.cs

@@ -380,7 +380,7 @@ namespace Jellyfin.Api.Helpers
         private void DeleteHlsPartialStreamFiles(string outputFilePath)
         {
             var directory = Path.GetDirectoryName(outputFilePath)
-                ?? throw new ArgumentException("Path can't be a root directory.", nameof(outputFilePath));
+                            ?? throw new ArgumentException("Path can't be a root directory.", nameof(outputFilePath));
 
             var name = Path.GetFileNameWithoutExtension(outputFilePath);
 
@@ -444,8 +444,10 @@ namespace Jellyfin.Api.Helpers
             {
                 var audioCodec = state.ActualOutputAudioCodec;
                 var videoCodec = state.ActualOutputVideoCodec;
-                var hardwareAccelerationType = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType;
-                hardwareAccelerationType = string.IsNullOrEmpty(hardwareAccelerationType) ? "none" : hardwareAccelerationType;
+                var hardwareAccelerationTypeString = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType;
+                HardwareEncodingType? hardwareAccelerationType = string.IsNullOrEmpty(hardwareAccelerationTypeString)
+                    ? null
+                    : (HardwareEncodingType)Enum.Parse(typeof(HardwareEncodingType), hardwareAccelerationTypeString, true);
 
                 _sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
                 {
@@ -762,8 +764,8 @@ namespace Jellyfin.Api.Helpers
             if (state.MediaSource.RequiresOpening && string.IsNullOrWhiteSpace(state.Request.LiveStreamId))
             {
                 var liveStreamResponse = await _mediaSourceManager.OpenLiveStream(
-                    new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken },
-                    cancellationTokenSource.Token)
+                        new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken },
+                        cancellationTokenSource.Token)
                     .ConfigureAwait(false);
                 var encodingOptions = _serverConfigurationManager.GetEncodingOptions();
 

+ 48 - 0
MediaBrowser.Model/Session/HardwareEncodingType.cs

@@ -0,0 +1,48 @@
+namespace MediaBrowser.Model.Session
+{
+    /// <summary>
+    /// Enum HardwareEncodingType.
+    /// </summary>
+    public enum HardwareEncodingType
+    {
+        /// <summary>
+        /// AMD AMF
+        /// </summary>
+        AMF,
+
+        /// <summary>
+        /// Intel Quick Sync Video
+        /// </summary>
+        QSV,
+
+        /// <summary>
+        /// NVIDIA NVENC
+        /// </summary>
+        NVENC,
+
+        /// <summary>
+        /// OpenMax OMX
+        /// </summary>
+        OMX,
+
+        /// <summary>
+        /// Exynos V4L2 MFC
+        /// </summary>
+        V4L2M2M,
+
+        /// <summary>
+        /// MediaCodec Android
+        /// </summary>
+        MediaCodec,
+
+        /// <summary>
+        /// Video Acceleration API (VAAPI)
+        /// </summary>
+        VAAPI,
+
+        /// <summary>
+        /// Video ToolBox
+        /// </summary>
+        VideoToolBox
+    }
+}

+ 1 - 1
MediaBrowser.Model/Session/TranscodingInfo.cs

@@ -34,7 +34,7 @@ namespace MediaBrowser.Model.Session
 
         public int? AudioChannels { get; set; }
 
-        public string HardwareAccelerationType { get; set; }
+        public HardwareEncodingType? HardwareAccelerationType { get; set; }
 
         public TranscodeReason[] TranscodeReasons { get; set; }
     }