From 7e3c94d094732c3c174375b0025604f1faa28f9e Mon Sep 17 00:00:00 2001 From: Brandon Nguyen Date: Sat, 3 Jul 2021 01:12:09 -0700 Subject: [PATCH 1/4] Add hardware encoding status to playback data Resolves #6087 --- CONTRIBUTORS.md | 1 + Jellyfin.Api/Helpers/TranscodingJobHelper.cs | 1 + MediaBrowser.Model/Session/TranscodingInfo.cs | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b44961bf8d..c2d2aff341 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -212,3 +212,4 @@ - [Tim Hobbs](https://github.com/timhobbs) - [SvenVandenbrande](https://github.com/SvenVandenbrande) - [olsh](https://github.com/olsh) + - [gnuyent](https://github.com/gnuyent) diff --git a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs index c295af7eb3..9e63638902 100644 --- a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs +++ b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs @@ -458,6 +458,7 @@ namespace Jellyfin.Api.Helpers AudioChannels = state.OutputAudioChannels, IsAudioDirect = EncodingHelper.IsCopyCodec(state.OutputAudioCodec), IsVideoDirect = EncodingHelper.IsCopyCodec(state.OutputVideoCodec), + IsHardwareEncode = !string.IsNullOrEmpty(_serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType), TranscodeReasons = state.TranscodeReasons }); } diff --git a/MediaBrowser.Model/Session/TranscodingInfo.cs b/MediaBrowser.Model/Session/TranscodingInfo.cs index 064a087d5d..98f3268b9b 100644 --- a/MediaBrowser.Model/Session/TranscodingInfo.cs +++ b/MediaBrowser.Model/Session/TranscodingInfo.cs @@ -34,6 +34,8 @@ namespace MediaBrowser.Model.Session public int? AudioChannels { get; set; } + public bool IsHardwareEncode { get; set; } + public TranscodeReason[] TranscodeReasons { get; set; } } } From df17c67f11468a645a2630401178bbd35b489c80 Mon Sep 17 00:00:00 2001 From: Brandon Nguyen Date: Sat, 3 Jul 2021 15:29:07 -0700 Subject: [PATCH 2/4] Use hardware encoding string over boolean --- Jellyfin.Api/Helpers/TranscodingJobHelper.cs | 4 +++- MediaBrowser.Model/Session/TranscodingInfo.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs index 9e63638902..b8a8491adc 100644 --- a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs +++ b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs @@ -444,6 +444,8 @@ namespace Jellyfin.Api.Helpers { var audioCodec = state.ActualOutputAudioCodec; var videoCodec = state.ActualOutputVideoCodec; + var hardwareAccelerationType = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType; + hardwareAccelerationType = string.IsNullOrEmpty(hardwareAccelerationType) ? "none" : hardwareAccelerationType; _sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo { @@ -458,7 +460,7 @@ namespace Jellyfin.Api.Helpers AudioChannels = state.OutputAudioChannels, IsAudioDirect = EncodingHelper.IsCopyCodec(state.OutputAudioCodec), IsVideoDirect = EncodingHelper.IsCopyCodec(state.OutputVideoCodec), - IsHardwareEncode = !string.IsNullOrEmpty(_serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType), + HardwareAccelerationType = hardwareAccelerationType, TranscodeReasons = state.TranscodeReasons }); } diff --git a/MediaBrowser.Model/Session/TranscodingInfo.cs b/MediaBrowser.Model/Session/TranscodingInfo.cs index 98f3268b9b..57f0a322e6 100644 --- a/MediaBrowser.Model/Session/TranscodingInfo.cs +++ b/MediaBrowser.Model/Session/TranscodingInfo.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Model.Session public int? AudioChannels { get; set; } - public bool IsHardwareEncode { get; set; } + public string HardwareAccelerationType { get; set; } public TranscodeReason[] TranscodeReasons { get; set; } } From d0c5e25ec05c8d2bb77cfe067db0a5ac2e338f15 Mon Sep 17 00:00:00 2001 From: Brandon Nguyen Date: Mon, 5 Jul 2021 16:52:52 -0700 Subject: [PATCH 3/4] Use nullable enum type instead of strings --- Jellyfin.Api/Helpers/TranscodingJobHelper.cs | 12 +++-- .../Session/HardwareEncodingType.cs | 48 +++++++++++++++++++ MediaBrowser.Model/Session/TranscodingInfo.cs | 2 +- 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 MediaBrowser.Model/Session/HardwareEncodingType.cs diff --git a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs index b8a8491adc..05fa5b1350 100644 --- a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs +++ b/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(); diff --git a/MediaBrowser.Model/Session/HardwareEncodingType.cs b/MediaBrowser.Model/Session/HardwareEncodingType.cs new file mode 100644 index 0000000000..11721f0907 --- /dev/null +++ b/MediaBrowser.Model/Session/HardwareEncodingType.cs @@ -0,0 +1,48 @@ +namespace MediaBrowser.Model.Session +{ + /// + /// Enum HardwareEncodingType. + /// + public enum HardwareEncodingType + { + /// + /// AMD AMF + /// + AMF, + + /// + /// Intel Quick Sync Video + /// + QSV, + + /// + /// NVIDIA NVENC + /// + NVENC, + + /// + /// OpenMax OMX + /// + OMX, + + /// + /// Exynos V4L2 MFC + /// + V4L2M2M, + + /// + /// MediaCodec Android + /// + MediaCodec, + + /// + /// Video Acceleration API (VAAPI) + /// + VAAPI, + + /// + /// Video ToolBox + /// + VideoToolBox + } +} diff --git a/MediaBrowser.Model/Session/TranscodingInfo.cs b/MediaBrowser.Model/Session/TranscodingInfo.cs index 57f0a322e6..68ab691f88 100644 --- a/MediaBrowser.Model/Session/TranscodingInfo.cs +++ b/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; } } From c6bac310427fed99b2e798cb785935c6f9f09b81 Mon Sep 17 00:00:00 2001 From: Brandon Nguyen Date: Sun, 11 Jul 2021 11:59:03 -0700 Subject: [PATCH 4/4] Add int values to HardwareEncodingType enum --- .../Session/HardwareEncodingType.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Model/Session/HardwareEncodingType.cs b/MediaBrowser.Model/Session/HardwareEncodingType.cs index 11721f0907..0e172f35f3 100644 --- a/MediaBrowser.Model/Session/HardwareEncodingType.cs +++ b/MediaBrowser.Model/Session/HardwareEncodingType.cs @@ -8,41 +8,41 @@ /// /// AMD AMF /// - AMF, + AMF = 0, /// /// Intel Quick Sync Video /// - QSV, + QSV = 1, /// /// NVIDIA NVENC /// - NVENC, + NVENC = 2, /// /// OpenMax OMX /// - OMX, + OMX = 3, /// /// Exynos V4L2 MFC /// - V4L2M2M, + V4L2M2M = 4, /// /// MediaCodec Android /// - MediaCodec, + MediaCodec = 5, /// /// Video Acceleration API (VAAPI) /// - VAAPI, + VAAPI = 6, /// /// Video ToolBox /// - VideoToolBox + VideoToolBox = 7 } }