Explorar o código

Fix ArgumentNullException on playlist creation (#13837)

mediaSourceId can be null, the IDE doesn't know this as nullable is disabled for BaseEncodingJobOptions
Bond-009 hai 2 meses
pai
achega
1c2b48182a

+ 2 - 2
Jellyfin.Api/Controllers/DynamicHlsController.cs

@@ -1419,9 +1419,9 @@ public class DynamicHlsController : BaseJellyfinApiController
                 TranscodingJobType,
                 cancellationTokenSource.Token)
             .ConfigureAwait(false);
-
+        var mediaSourceId = state.BaseRequest.MediaSourceId;
         var request = new CreateMainPlaylistRequest(
-            Guid.Parse(state.BaseRequest.MediaSourceId),
+            mediaSourceId is null ? null : Guid.Parse(mediaSourceId),
             state.MediaPath,
             state.SegmentLength * 1000,
             state.RunTimeTicks ?? 0,

+ 2 - 2
src/Jellyfin.MediaEncoding.Hls/Playlist/CreateMainPlaylistRequest.cs

@@ -18,7 +18,7 @@ public class CreateMainPlaylistRequest
     /// <param name="endpointPrefix">The URI prefix for the relative URL in the playlist.</param>
     /// <param name="queryString">The desired query string to append (must start with ?).</param>
     /// <param name="isRemuxingVideo">Whether the video is being remuxed.</param>
-    public CreateMainPlaylistRequest(Guid mediaSourceId, string filePath, int desiredSegmentLengthMs, long totalRuntimeTicks, string segmentContainer, string endpointPrefix, string queryString, bool isRemuxingVideo)
+    public CreateMainPlaylistRequest(Guid? mediaSourceId, string filePath, int desiredSegmentLengthMs, long totalRuntimeTicks, string segmentContainer, string endpointPrefix, string queryString, bool isRemuxingVideo)
     {
         MediaSourceId = mediaSourceId;
         FilePath = filePath;
@@ -33,7 +33,7 @@ public class CreateMainPlaylistRequest
     /// <summary>
     /// Gets the media source id.
     /// </summary>
-    public Guid MediaSourceId { get; }
+    public Guid? MediaSourceId { get; }
 
     /// <summary>
     /// Gets the file path.

+ 3 - 1
src/Jellyfin.MediaEncoding.Hls/Playlist/DynamicHlsPlaylistGenerator.cs

@@ -35,7 +35,9 @@ public class DynamicHlsPlaylistGenerator : IDynamicHlsPlaylistGenerator
     {
         IReadOnlyList<double> segments;
         // For video transcodes it is sufficient with equal length segments as ffmpeg will create new keyframes
-        if (request.IsRemuxingVideo && TryExtractKeyframes(request.MediaSourceId, request.FilePath, out var keyframeData))
+        if (request.IsRemuxingVideo
+            && request.MediaSourceId is not null
+            && TryExtractKeyframes(request.MediaSourceId.Value, request.FilePath, out var keyframeData))
         {
             segments = ComputeSegments(keyframeData, request.DesiredSegmentLengthMs);
         }