From 9cdf87e602fa6718f5a293db2c249af1422fa9a9 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 11 May 2024 13:26:22 -0600 Subject: [PATCH] 10.9 (#44) --- .../IDlnaManager.cs | 3 +- .../Jellyfin.Plugin.Dlna.Model.csproj | 6 +-- .../Api/DlnaVideosController.cs | 2 +- .../FileStreamResponseHelpers.cs | 41 ++++++++----------- .../Jellyfin.Plugin.Dlna.Playback.csproj | 4 +- .../Api/DlnaServerController.cs | 6 +-- src/Jellyfin.Plugin.Dlna/DlnaManager.cs | 17 +------- .../Extensions/StreamInfoExtensions.cs | 11 ++--- .../Jellyfin.Plugin.Dlna.csproj | 4 +- src/Rssdp/Rssdp.csproj | 8 ++-- 10 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/Jellyfin.Plugin.Dlna.Model/IDlnaManager.cs b/src/Jellyfin.Plugin.Dlna.Model/IDlnaManager.cs index a5f5eab..ff62401 100644 --- a/src/Jellyfin.Plugin.Dlna.Model/IDlnaManager.cs +++ b/src/Jellyfin.Plugin.Dlna.Model/IDlnaManager.cs @@ -1,6 +1,7 @@ #pragma warning disable CS1591 using System.Collections.Generic; +using System.IO; using MediaBrowser.Controller.Drawing; using MediaBrowser.Model.Dlna; using Microsoft.AspNetCore.Http; @@ -75,5 +76,5 @@ public interface IDlnaManager /// /// The filename. /// DlnaIconResponse. - ImageStream? GetIcon(string filename); + Stream? GetIcon(string filename); } diff --git a/src/Jellyfin.Plugin.Dlna.Model/Jellyfin.Plugin.Dlna.Model.csproj b/src/Jellyfin.Plugin.Dlna.Model/Jellyfin.Plugin.Dlna.Model.csproj index d8104b1..7e2be85 100644 --- a/src/Jellyfin.Plugin.Dlna.Model/Jellyfin.Plugin.Dlna.Model.csproj +++ b/src/Jellyfin.Plugin.Dlna.Model/Jellyfin.Plugin.Dlna.Model.csproj @@ -5,8 +5,8 @@ - - - + + + diff --git a/src/Jellyfin.Plugin.Dlna.Playback/Api/DlnaVideosController.cs b/src/Jellyfin.Plugin.Dlna.Playback/Api/DlnaVideosController.cs index d7d6815..9cba84f 100644 --- a/src/Jellyfin.Plugin.Dlna.Playback/Api/DlnaVideosController.cs +++ b/src/Jellyfin.Plugin.Dlna.Playback/Api/DlnaVideosController.cs @@ -318,7 +318,7 @@ public async Task GetVideoStream( // Need to start ffmpeg (because media can't be returned directly) var encodingOptions = _serverConfigurationManager.GetEncodingOptions(); - var ffmpegCommandLineArguments = _encodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, outputPath, "superfast"); + var ffmpegCommandLineArguments = _encodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, "superfast"); return await FileStreamResponseHelpers.GetTranscodedFile( state, isHeadRequest, diff --git a/src/Jellyfin.Plugin.Dlna.Playback/FileStreamResponseHelpers.cs b/src/Jellyfin.Plugin.Dlna.Playback/FileStreamResponseHelpers.cs index 3acfa76..e533006 100644 --- a/src/Jellyfin.Plugin.Dlna.Playback/FileStreamResponseHelpers.cs +++ b/src/Jellyfin.Plugin.Dlna.Playback/FileStreamResponseHelpers.cs @@ -93,33 +93,26 @@ public static async Task GetTranscodedFile( return new OkResult(); } - var transcodingLock = transcodeManager.GetTranscodingLock(outputPath); - await transcodingLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); - try - { - TranscodingJob? job; - if (!File.Exists(outputPath)) - { - job = await transcodeManager.StartFfMpeg( - state, - outputPath, - ffmpegCommandLineArguments, - httpContext.User.GetUserId(), - transcodingJobType, - cancellationTokenSource).ConfigureAwait(false); - } - else - { - job = transcodeManager.OnTranscodeBeginRequest(outputPath, TranscodingJobType.Progressive); - state.Dispose(); - } + using var transcodingLock = await transcodeManager.LockAsync(outputPath, cancellationTokenSource.Token); - var stream = new ProgressiveFileStream(outputPath, job, transcodeManager); - return new FileStreamResult(stream, contentType); + TranscodingJob? job; + if (!File.Exists(outputPath)) + { + job = await transcodeManager.StartFfMpeg( + state, + outputPath, + ffmpegCommandLineArguments, + httpContext.User.GetUserId(), + transcodingJobType, + cancellationTokenSource).ConfigureAwait(false); } - finally + else { - transcodingLock.Release(); + job = transcodeManager.OnTranscodeBeginRequest(outputPath, TranscodingJobType.Progressive); + state.Dispose(); } + + var stream = new ProgressiveFileStream(outputPath, job, transcodeManager); + return new FileStreamResult(stream, contentType); } } diff --git a/src/Jellyfin.Plugin.Dlna.Playback/Jellyfin.Plugin.Dlna.Playback.csproj b/src/Jellyfin.Plugin.Dlna.Playback/Jellyfin.Plugin.Dlna.Playback.csproj index 992455f..9565059 100644 --- a/src/Jellyfin.Plugin.Dlna.Playback/Jellyfin.Plugin.Dlna.Playback.csproj +++ b/src/Jellyfin.Plugin.Dlna.Playback/Jellyfin.Plugin.Dlna.Playback.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs index 98e9dc8..a322d7c 100644 --- a/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs +++ b/src/Jellyfin.Plugin.Dlna/Api/DlnaServerController.cs @@ -265,13 +265,13 @@ public ActionResult GetIcon([FromRoute, Required] string fileName) private ActionResult GetIconInternal(string fileName) { - var icon = _dlnaManager.GetIcon(fileName); - if (icon is null) + var iconStream = _dlnaManager.GetIcon(fileName); + if (iconStream is null) { return NotFound(); } - return File(icon.Stream, MimeTypes.GetMimeType(fileName)); + return File(iconStream, MimeTypes.GetMimeType(fileName)); } private string GetAbsoluteUri() diff --git a/src/Jellyfin.Plugin.Dlna/DlnaManager.cs b/src/Jellyfin.Plugin.Dlna/DlnaManager.cs index 4013446..24f62c1 100644 --- a/src/Jellyfin.Plugin.Dlna/DlnaManager.cs +++ b/src/Jellyfin.Plugin.Dlna/DlnaManager.cs @@ -458,23 +458,10 @@ public string GetServerDescriptionXml(IHeaderDictionary headers, string serverUu } /// - public ImageStream? GetIcon(string filename) + public Stream? GetIcon(string filename) { - var format = filename.EndsWith(".png", StringComparison.OrdinalIgnoreCase) - ? ImageFormat.Png - : ImageFormat.Jpg; - var resource = GetType().Namespace + ".Images." + filename.ToLowerInvariant(); - var stream = _assembly.GetManifestResourceStream(resource); - if (stream is null) - { - return null; - } - - return new ImageStream(stream) - { - Format = format - }; + return _assembly.GetManifestResourceStream(resource); } private class InternalProfileInfo diff --git a/src/Jellyfin.Plugin.Dlna/Extensions/StreamInfoExtensions.cs b/src/Jellyfin.Plugin.Dlna/Extensions/StreamInfoExtensions.cs index b23f755..20f8577 100644 --- a/src/Jellyfin.Plugin.Dlna/Extensions/StreamInfoExtensions.cs +++ b/src/Jellyfin.Plugin.Dlna/Extensions/StreamInfoExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using Jellyfin.Data.Enums; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; @@ -60,7 +61,7 @@ private static string GetUrl(StreamInfo streamInfo, string baseUrl, string query var itemId = streamInfo.ItemId; if (streamInfo.MediaType == DlnaProfileType.Audio) { - if (string.Equals(streamInfo.SubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) + if (streamInfo.SubProtocol == MediaStreamProtocol.hls) { return string.Format(CultureInfo.InvariantCulture, "{0}/dlna/audio/{1}/master.m3u8?{2}", baseUrl, itemId, queryString); } @@ -68,14 +69,14 @@ private static string GetUrl(StreamInfo streamInfo, string baseUrl, string query return string.Format(CultureInfo.InvariantCulture, "{0}/dlna/audio/{1}/stream{2}?{3}", baseUrl, itemId, extension, queryString); } - if (string.Equals(streamInfo.SubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) + if (streamInfo.SubProtocol == MediaStreamProtocol.hls) { return string.Format(CultureInfo.InvariantCulture, "{0}/dlna/videos/{1}/master.m3u8?{2}", baseUrl, itemId, queryString); } return string.Format(CultureInfo.InvariantCulture, "{0}/dlna/videos/{1}/stream{2}?{3}", baseUrl, itemId, extension, queryString); } - + private static IEnumerable BuildParams(StreamInfo item, string? accessToken) { var list = new List(); @@ -105,7 +106,7 @@ private static IEnumerable BuildParams(StreamInfo item, string? a list.Add(new NameValuePair("MaxHeight", item.MaxHeight.HasValue ? item.MaxHeight.Value.ToString(CultureInfo.InvariantCulture) : string.Empty)); long startPositionTicks = item.StartPositionTicks; - var isHls = string.Equals(item.SubProtocol, "hls", StringComparison.OrdinalIgnoreCase); + var isHls = item.SubProtocol == MediaStreamProtocol.hls; if (isHls) { @@ -204,4 +205,4 @@ private static IEnumerable BuildParams(StreamInfo item, string? a return list; } -} \ No newline at end of file +} diff --git a/src/Jellyfin.Plugin.Dlna/Jellyfin.Plugin.Dlna.csproj b/src/Jellyfin.Plugin.Dlna/Jellyfin.Plugin.Dlna.csproj index a2e66c4..6f6ca2d 100644 --- a/src/Jellyfin.Plugin.Dlna/Jellyfin.Plugin.Dlna.csproj +++ b/src/Jellyfin.Plugin.Dlna/Jellyfin.Plugin.Dlna.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/Rssdp/Rssdp.csproj b/src/Rssdp/Rssdp.csproj index c7badf9..0b937f8 100644 --- a/src/Rssdp/Rssdp.csproj +++ b/src/Rssdp/Rssdp.csproj @@ -5,9 +5,9 @@ - - - - + + + +