diff options
Diffstat (limited to 'Jellyfin.Api/Helpers')
| -rw-r--r-- | Jellyfin.Api/Helpers/AudioHelper.cs | 8 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/DynamicHlsHelper.cs | 60 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs | 16 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/HlsHelpers.cs | 4 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/MediaInfoHelper.cs | 14 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/ProgressiveFileStream.cs | 4 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/RequestHelpers.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/StreamingHelpers.cs | 64 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/TranscodingJobHelper.cs | 28 |
9 files changed, 123 insertions, 77 deletions
diff --git a/Jellyfin.Api/Helpers/AudioHelper.cs b/Jellyfin.Api/Helpers/AudioHelper.cs index bc83ff48a..be410ebcd 100644 --- a/Jellyfin.Api/Helpers/AudioHelper.cs +++ b/Jellyfin.Api/Helpers/AudioHelper.cs @@ -85,7 +85,7 @@ namespace Jellyfin.Api.Helpers TranscodingJobType transcodingJobType, StreamingRequestDto streamingRequest) { - if (_httpContextAccessor.HttpContext == null) + if (_httpContextAccessor.HttpContext is null) { throw new ResourceNotFoundException(nameof(_httpContextAccessor.HttpContext)); } @@ -111,12 +111,12 @@ namespace Jellyfin.Api.Helpers cancellationTokenSource.Token) .ConfigureAwait(false); - if (streamingRequest.Static && state.DirectStreamProvider != null) + if (streamingRequest.Static && state.DirectStreamProvider is not null) { StreamingHelpers.AddDlnaHeaders(state, _httpContextAccessor.HttpContext.Response.Headers, true, streamingRequest.StartTimeTicks, _httpContextAccessor.HttpContext.Request, _dlnaManager); var liveStreamInfo = _mediaSourceManager.GetLiveStreamInfo(streamingRequest.LiveStreamId); - if (liveStreamInfo == null) + if (liveStreamInfo is null) { throw new FileNotFoundException(); } @@ -144,7 +144,7 @@ namespace Jellyfin.Api.Helpers var outputPathExists = File.Exists(outputPath); var transcodingJob = _transcodingJobHelper.GetTranscodingJob(outputPath, TranscodingJobType.Progressive); - var isTranscodeCached = outputPathExists && transcodingJob != null; + var isTranscodeCached = outputPathExists && transcodingJob is not null; StreamingHelpers.AddDlnaHeaders(state, _httpContextAccessor.HttpContext.Response.Headers, streamingRequest.Static || isTranscodeCached, streamingRequest.StartTimeTicks, _httpContextAccessor.HttpContext.Request, _dlnaManager); diff --git a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs index fa392e567..010b181f7 100644 --- a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs +++ b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs @@ -117,7 +117,7 @@ namespace Jellyfin.Api.Helpers TranscodingJobType transcodingJobType, CancellationTokenSource cancellationTokenSource) { - if (_httpContextAccessor.HttpContext == null) + if (_httpContextAccessor.HttpContext is null) { throw new ResourceNotFoundException(nameof(_httpContextAccessor.HttpContext)); } @@ -183,7 +183,7 @@ namespace Jellyfin.Api.Helpers : null; // If we're burning in subtitles then don't add additional subs to the manifest - if (state.SubtitleStream != null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode) + if (state.SubtitleStream is not null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode) { subtitleGroup = null; } @@ -195,8 +195,15 @@ namespace Jellyfin.Api.Helpers var basicPlaylist = AppendPlaylist(builder, state, playlistUrl, totalBitrate, subtitleGroup); - if (state.VideoStream != null && state.VideoRequest != null) + if (state.VideoStream is not null && state.VideoRequest is not null) { + // Provide a workaround for the case issue between flac and fLaC. + var flacWaPlaylist = ApplyFlacCaseWorkaround(state, basicPlaylist.ToString()); + if (!string.IsNullOrEmpty(flacWaPlaylist)) + { + builder.Append(flacWaPlaylist); + } + // Provide SDR HEVC entrance for backward compatibility. if (EncodingHelper.IsCopyCodec(state.OutputVideoCodec) && !string.IsNullOrEmpty(state.VideoStream.VideoRange) @@ -204,7 +211,7 @@ namespace Jellyfin.Api.Helpers && string.Equals(state.ActualOutputVideoCodec, "hevc", StringComparison.OrdinalIgnoreCase)) { var requestedVideoProfiles = state.GetRequestedProfiles("hevc"); - if (requestedVideoProfiles != null && requestedVideoProfiles.Length > 0) + if (requestedVideoProfiles is not null && requestedVideoProfiles.Length > 0) { // Force HEVC Main Profile and disable video stream copy. state.OutputVideoCodec = "hevc"; @@ -215,7 +222,14 @@ namespace Jellyfin.Api.Helpers var sdrOutputAudioBitrate = _encodingHelper.GetAudioBitrateParam(state.VideoRequest, state.AudioStream) ?? 0; var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate; - AppendPlaylist(builder, state, sdrVideoUrl, sdrTotalBitrate, subtitleGroup); + var sdrPlaylist = AppendPlaylist(builder, state, sdrVideoUrl, sdrTotalBitrate, subtitleGroup); + + // Provide a workaround for the case issue between flac and fLaC. + flacWaPlaylist = ApplyFlacCaseWorkaround(state, sdrPlaylist.ToString()); + if (!string.IsNullOrEmpty(flacWaPlaylist)) + { + builder.Append(flacWaPlaylist); + } // Restore the video codec state.OutputVideoCodec = "copy"; @@ -245,12 +259,19 @@ namespace Jellyfin.Api.Helpers state.VideoStream.Level = originalLevel; var newPlaylist = ReplacePlaylistCodecsField(basicPlaylist, playlistCodecsField, newPlaylistCodecsField); builder.Append(newPlaylist); + + // Provide a workaround for the case issue between flac and fLaC. + flacWaPlaylist = ApplyFlacCaseWorkaround(state, newPlaylist); + if (!string.IsNullOrEmpty(flacWaPlaylist)) + { + builder.Append(flacWaPlaylist); + } } } if (EnableAdaptiveBitrateStreaming(state, isLiveStream, enableAdaptiveBitrateStreaming, _httpContextAccessor.HttpContext.GetNormalizedRemoteIp())) { - var requestedVideoBitrate = state.VideoRequest == null ? 0 : state.VideoRequest.VideoBitRate ?? 0; + var requestedVideoBitrate = state.VideoRequest is null ? 0 : state.VideoRequest.VideoBitRate ?? 0; // By default, vary by just 200k var variation = GetBitrateVariation(totalBitrate); @@ -306,7 +327,7 @@ namespace Jellyfin.Api.Helpers /// <param name="state">StreamState of the current stream.</param> private void AppendPlaylistVideoRangeField(StringBuilder builder, StreamState state) { - if (state.VideoStream != null && !string.IsNullOrEmpty(state.VideoStream.VideoRange)) + if (state.VideoStream is not null && !string.IsNullOrEmpty(state.VideoStream.VideoRange)) { var videoRange = state.VideoStream.VideoRange; if (EncodingHelper.IsCopyCodec(state.OutputVideoCodec)) @@ -404,7 +425,7 @@ namespace Jellyfin.Api.Helpers { framerate = Math.Round(state.TargetFramerate.GetValueOrDefault(), 3); } - else if (state.VideoStream?.RealFrameRate != null) + else if (state.VideoStream?.RealFrameRate is not null) { framerate = Math.Round(state.VideoStream.RealFrameRate.GetValueOrDefault(), 3); } @@ -462,7 +483,7 @@ namespace Jellyfin.Api.Helpers return; } - var selectedIndex = state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Hls ? (int?)null : state.SubtitleStream.Index; + var selectedIndex = state.SubtitleStream is null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Hls ? (int?)null : state.SubtitleStream.Index; const string Format = "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"{0}\",DEFAULT={1},FORCED={2},AUTOSELECT=YES,URI=\"{3}\",LANGUAGE=\"{4}\""; foreach (var stream in subtitles) @@ -502,7 +523,7 @@ namespace Jellyfin.Api.Helpers { string levelString = string.Empty; if (EncodingHelper.IsCopyCodec(state.OutputVideoCodec) - && state.VideoStream != null + && state.VideoStream is not null && state.VideoStream.Level.HasValue) { levelString = state.VideoStream.Level.ToString() ?? string.Empty; @@ -603,6 +624,11 @@ namespace Jellyfin.Api.Helpers return HlsCodecStringHelpers.GetALACString(); } + if (string.Equals(state.ActualOutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase)) + { + return HlsCodecStringHelpers.GetOPUSString(); + } + return string.Empty; } @@ -701,7 +727,19 @@ namespace Jellyfin.Api.Helpers return oldPlaylist.Replace( oldValue.ToString(), newValue.ToString(), - StringComparison.OrdinalIgnoreCase); + StringComparison.Ordinal); + } + + private string ApplyFlacCaseWorkaround(StreamState state, string srcPlaylist) + { + if (!string.Equals(state.ActualOutputAudioCodec, "flac", StringComparison.OrdinalIgnoreCase)) + { + return string.Empty; + } + + var newPlaylist = srcPlaylist.Replace(",flac\"", ",fLaC\"", StringComparison.Ordinal); + + return newPlaylist.Contains(",fLaC\"", StringComparison.Ordinal) ? newPlaylist : string.Empty; } } } diff --git a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs index a5369c441..cbe82979b 100644 --- a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs +++ b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs @@ -27,7 +27,7 @@ namespace Jellyfin.Api.Helpers /// <summary> /// Codec name for FLAC. /// </summary> - public const string FLAC = "fLaC"; + public const string FLAC = "flac"; /// <summary> /// Codec name for ALAC. @@ -35,6 +35,11 @@ namespace Jellyfin.Api.Helpers public const string ALAC = "alac"; /// <summary> + /// Codec name for OPUS. + /// </summary> + public const string OPUS = "opus"; + + /// <summary> /// Gets a MP3 codec string. /// </summary> /// <returns>MP3 codec string.</returns> @@ -102,6 +107,15 @@ namespace Jellyfin.Api.Helpers } /// <summary> + /// Gets an OPUS codec string. + /// </summary> + /// <returns>OPUS codec string.</returns> + public static string GetOPUSString() + { + return OPUS; + } + + /// <summary> /// Gets a H.264 codec string. /// </summary> /// <param name="profile">H.264 profile.</param> diff --git a/Jellyfin.Api/Helpers/HlsHelpers.cs b/Jellyfin.Api/Helpers/HlsHelpers.cs index 456762147..671107c1f 100644 --- a/Jellyfin.Api/Helpers/HlsHelpers.cs +++ b/Jellyfin.Api/Helpers/HlsHelpers.cs @@ -46,8 +46,8 @@ namespace Jellyfin.Api.Helpers while (!reader.EndOfStream) { - var line = await reader.ReadLineAsync().ConfigureAwait(false); - if (line == null) + var line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false); + if (line is null) { // Nothing currently in buffer. break; diff --git a/Jellyfin.Api/Helpers/MediaInfoHelper.cs b/Jellyfin.Api/Helpers/MediaInfoHelper.cs index 4441ae023..e8ce1ca2a 100644 --- a/Jellyfin.Api/Helpers/MediaInfoHelper.cs +++ b/Jellyfin.Api/Helpers/MediaInfoHelper.cs @@ -127,7 +127,7 @@ namespace Jellyfin.Api.Helpers // Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it // Should we move this directly into MediaSourceManager? var mediaSourcesClone = JsonSerializer.Deserialize<MediaSourceInfo[]>(JsonSerializer.SerializeToUtf8Bytes(mediaSources)); - if (mediaSourcesClone != null) + if (mediaSourcesClone is not null) { result.MediaSources = mediaSourcesClone; } @@ -247,7 +247,7 @@ namespace Jellyfin.Api.Helpers ? streamBuilder.BuildAudioItem(options) : streamBuilder.BuildVideoItem(options); - if (streamInfo != null) + if (streamInfo is not null) { streamInfo.PlaySessionId = playSessionId; streamInfo.StartPositionTicks = startTimeTicks; @@ -262,7 +262,7 @@ namespace Jellyfin.Api.Helpers mediaSource.SupportsTranscoding = streamInfo.PlayMethod == PlayMethod.DirectStream - || mediaSource.TranscodingContainer != null + || mediaSource.TranscodingContainer is not null || profile.TranscodingProfiles.Any(i => i.Type == streamInfo.MediaType && i.Context == options.Context); if (item is Audio) @@ -390,16 +390,16 @@ namespace Jellyfin.Api.Helpers var result = await _mediaSourceManager.OpenLiveStream(request, CancellationToken.None).ConfigureAwait(false); var profile = request.DeviceProfile; - if (profile == null) + if (profile is null) { var clientCapabilities = _deviceManager.GetCapabilities(httpContext.User.GetDeviceId()); - if (clientCapabilities != null) + if (clientCapabilities is not null) { profile = clientCapabilities.DeviceProfile; } } - if (profile != null) + if (profile is not null) { var item = _libraryManager.GetItemById(request.ItemId); @@ -431,7 +431,7 @@ namespace Jellyfin.Api.Helpers } } - // here was a check if (result.MediaSource != null) but Rider said it will never be null + // here was a check if (result.MediaSource is not null) but Rider said it will never be null NormalizeMediaSourceContainer(result.MediaSource, profile!, DlnaProfileType.Video); return result; diff --git a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs index 6f5b64ea8..dfeeea2b0 100644 --- a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs +++ b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs @@ -151,7 +151,7 @@ namespace Jellyfin.Api.Helpers { _stream.Dispose(); - if (_job != null) + if (_job is not null) { _transcodingJobHelper?.OnTranscodeEndRequest(_job); } @@ -166,7 +166,7 @@ namespace Jellyfin.Api.Helpers private void UpdateBytesWritten(int totalBytesRead) { - if (_job != null) + if (_job is not null) { _job.BytesDownloaded += totalBytesRead; } diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs index 8c5af013a..035d84513 100644 --- a/Jellyfin.Api/Helpers/RequestHelpers.cs +++ b/Jellyfin.Api/Helpers/RequestHelpers.cs @@ -96,7 +96,7 @@ namespace Jellyfin.Api.Helpers httpContext.GetNormalizedRemoteIp().ToString(), user).ConfigureAwait(false); - if (session == null) + if (session is null) { throw new ArgumentException("Session not found."); } diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs index c8e62999c..d4fc9c020 100644 --- a/Jellyfin.Api/Helpers/StreamingHelpers.cs +++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs @@ -76,7 +76,7 @@ namespace Jellyfin.Api.Helpers } streamingRequest.StreamOptions = ParseStreamOptions(httpRequest.Query); - if (httpRequest.Path.Value == null) + if (httpRequest.Path.Value is null) { throw new ResourceNotFoundException(nameof(httpRequest.Path)); } @@ -137,12 +137,12 @@ namespace Jellyfin.Api.Helpers ? transcodingJobHelper.GetTranscodingJob(streamingRequest.PlaySessionId) : null; - if (currentJob != null) + if (currentJob is not null) { mediaSource = currentJob.MediaSource; } - if (mediaSource == null) + if (mediaSource is null) { var mediaSources = await mediaSourceManager.GetPlaybackMediaSources(libraryManager.GetItemById(streamingRequest.Id), null, false, false, cancellationToken).ConfigureAwait(false); @@ -150,7 +150,7 @@ namespace Jellyfin.Api.Helpers ? mediaSources[0] : mediaSources.Find(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringComparison.Ordinal)); - if (mediaSource == null && Guid.Parse(streamingRequest.MediaSourceId).Equals(streamingRequest.Id)) + if (mediaSource is null && Guid.Parse(streamingRequest.MediaSourceId).Equals(streamingRequest.Id)) { mediaSource = mediaSources[0]; } @@ -189,7 +189,7 @@ namespace Jellyfin.Api.Helpers state.OutputAudioChannels = encodingHelper.GetNumAudioChannelsParam(state, state.AudioStream, state.OutputAudioCodec); - if (state.VideoRequest != null) + if (state.VideoRequest is not null) { state.OutputVideoCodec = state.Request.VideoCodec; state.OutputVideoBitrate = encodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec); @@ -204,7 +204,7 @@ namespace Jellyfin.Api.Helpers && !state.VideoRequest.MaxHeight.HasValue; if (isVideoResolutionNotRequested - && state.VideoStream != null + && state.VideoStream is not null && state.VideoRequest.VideoBitRate.HasValue && state.VideoStream.BitRate.HasValue && state.VideoRequest.VideoBitRate.Value >= state.VideoStream.BitRate.Value) @@ -281,7 +281,7 @@ namespace Jellyfin.Api.Helpers Convert.ToInt32(ms))); } - if (!isStaticallyStreamed && profile != null) + if (!isStaticallyStreamed && profile is not null) { AddTimeSeekResponseHeaders(state, responseHeaders, startTimeTicks); } @@ -364,9 +364,9 @@ namespace Jellyfin.Api.Helpers /// </summary> /// <param name="queryString">The query string.</param> /// <returns>A <see cref="Dictionary{String,String}"/> containing the stream options.</returns> - private static Dictionary<string, string> ParseStreamOptions(IQueryCollection queryString) + private static Dictionary<string, string?> ParseStreamOptions(IQueryCollection queryString) { - Dictionary<string, string> streamOptions = new Dictionary<string, string>(); + Dictionary<string, string?> streamOptions = new Dictionary<string, string?>(); foreach (var param in queryString) { if (char.IsLower(param.Key[0])) @@ -510,16 +510,16 @@ namespace Jellyfin.Api.Helpers { state.DeviceProfile = dlnaManager.GetProfile(deviceProfileId); - if (state.DeviceProfile == null) + if (state.DeviceProfile is null) { var caps = deviceManager.GetCapabilities(deviceProfileId); - state.DeviceProfile = caps == null ? dlnaManager.GetProfile(request.Headers) : caps.DeviceProfile; + state.DeviceProfile = caps is null ? dlnaManager.GetProfile(request.Headers) : caps.DeviceProfile; } } var profile = state.DeviceProfile; - if (profile == null) + if (profile is null) { // Don't use settings from the default profile. // Only use a specific profile if it was requested. @@ -553,7 +553,7 @@ namespace Jellyfin.Api.Helpers state.TargetVideoCodecTag, state.IsTargetAVC); - if (mediaProfile != null) + if (mediaProfile is not null) { state.MimeType = mediaProfile.MimeType; } @@ -562,13 +562,13 @@ namespace Jellyfin.Api.Helpers { var transcodingProfile = !state.IsVideoRequest ? profile.GetAudioTranscodingProfile(state.OutputContainer, audioCodec) : profile.GetVideoTranscodingProfile(state.OutputContainer, audioCodec, videoCodec); - if (transcodingProfile != null) + if (transcodingProfile is not null) { state.EstimateContentLength = transcodingProfile.EstimateContentLength; // state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; - if (state.VideoRequest != null) + if (state.VideoRequest is not null) { state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps; state.VideoRequest.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest; @@ -616,7 +616,7 @@ namespace Jellyfin.Api.Helpers request.Static = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); break; case 4: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.VideoCodec = val; } @@ -626,21 +626,21 @@ namespace Jellyfin.Api.Helpers request.AudioCodec = val; break; case 6: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.AudioStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); } break; case 7: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.SubtitleStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); } break; case 8: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.VideoBitRate = int.Parse(val, CultureInfo.InvariantCulture); } @@ -653,21 +653,21 @@ namespace Jellyfin.Api.Helpers request.MaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); break; case 11: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.MaxFramerate = float.Parse(val, CultureInfo.InvariantCulture); } break; case 12: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.MaxWidth = int.Parse(val, CultureInfo.InvariantCulture); } break; case 13: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.MaxHeight = int.Parse(val, CultureInfo.InvariantCulture); } @@ -677,28 +677,28 @@ namespace Jellyfin.Api.Helpers request.StartTimeTicks = long.Parse(val, CultureInfo.InvariantCulture); break; case 15: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.Level = val; } break; case 16: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.MaxRefFrames = int.Parse(val, CultureInfo.InvariantCulture); } break; case 17: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.MaxVideoBitDepth = int.Parse(val, CultureInfo.InvariantCulture); } break; case 18: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.Profile = val; } @@ -720,14 +720,14 @@ namespace Jellyfin.Api.Helpers // Duplicating ItemId because of MediaMonkey break; case 24: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; case 25: - if (!string.IsNullOrWhiteSpace(val) && videoRequest != null) + if (!string.IsNullOrWhiteSpace(val) && videoRequest is not null) { if (Enum.TryParse(val, out SubtitleDeliveryMethod method)) { @@ -740,7 +740,7 @@ namespace Jellyfin.Api.Helpers request.TranscodingMaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); break; case 27: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } @@ -750,7 +750,7 @@ namespace Jellyfin.Api.Helpers request.Tag = val; break; case 29: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } @@ -760,14 +760,14 @@ namespace Jellyfin.Api.Helpers request.SubtitleCodec = val; break; case 31: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.RequireNonAnamorphic = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; case 32: - if (videoRequest != null) + if (videoRequest is not null) { videoRequest.DeInterlace = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } diff --git a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs index c663c6e31..77dd51860 100644 --- a/Jellyfin.Api/Helpers/TranscodingJobHelper.cs +++ b/Jellyfin.Api/Helpers/TranscodingJobHelper.cs @@ -136,10 +136,7 @@ namespace Jellyfin.Api.Helpers /// <exception cref="ArgumentNullException">Play session id is null.</exception> public void PingTranscodingJob(string playSessionId, bool? isUserPaused) { - if (string.IsNullOrEmpty(playSessionId)) - { - throw new ArgumentNullException(nameof(playSessionId)); - } + ArgumentException.ThrowIfNullOrEmpty(playSessionId); _logger.LogDebug("PingTranscodingJob PlaySessionId={0} isUsedPaused: {1}", playSessionId, isUserPaused); @@ -416,7 +413,7 @@ namespace Jellyfin.Api.Helpers } } - if (exs != null) + if (exs is not null) { throw new AggregateException("Error deleting HLS files", exs); } @@ -443,7 +440,7 @@ namespace Jellyfin.Api.Helpers { var ticks = transcodingPosition?.Ticks; - if (job != null) + if (job is not null) { job.Framerate = framerate; job.CompletionPercentage = percentComplete; @@ -510,11 +507,11 @@ namespace Jellyfin.Api.Helpers await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false); - if (state.VideoRequest != null && !EncodingHelper.IsCopyCodec(state.OutputVideoCodec)) + if (state.VideoRequest is not null && !EncodingHelper.IsCopyCodec(state.OutputVideoCodec)) { var userId = request.HttpContext.User.GetUserId(); var user = userId.Equals(default) ? null : _userManager.GetUserById(userId); - if (user != null && !user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding)) + if (user is not null && !user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding)) { this.OnTranscodeFailedToStart(outputPath, transcodingJobType, state); @@ -522,13 +519,10 @@ namespace Jellyfin.Api.Helpers } } - if (string.IsNullOrEmpty(_mediaEncoder.EncoderPath)) - { - throw new ArgumentException("FFmpeg path not set."); - } + ArgumentException.ThrowIfNullOrEmpty(_mediaEncoder.EncoderPath); // If subtitles get burned in fonts may need to be extracted from the media file - if (state.SubtitleStream != null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode) + if (state.SubtitleStream is not null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode) { var attachmentPath = Path.Combine(_appPaths.CachePath, "attachments", state.MediaSource.Id); await _attachmentExtractor.ExtractAllAttachments(state.MediaPath, state.MediaSource, attachmentPath, cancellationTokenSource.Token).ConfigureAwait(false); @@ -577,7 +571,7 @@ namespace Jellyfin.Api.Helpers _logger.LogInformation("{Filename} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments); var logFilePrefix = "FFmpeg.Transcode-"; - if (state.VideoRequest != null + if (state.VideoRequest is not null && EncodingHelper.IsCopyCodec(state.OutputVideoCodec)) { logFilePrefix = EncodingHelper.IsCopyCodec(state.OutputAudioCodec) @@ -748,7 +742,7 @@ namespace Jellyfin.Api.Helpers { var job = _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && string.Equals(j.Path, path, StringComparison.OrdinalIgnoreCase)); - if (job != null) + if (job is not null) { _activeTranscodingJobs.Remove(job); } @@ -805,7 +799,7 @@ namespace Jellyfin.Api.Helpers _encodingHelper.AttachMediaSourceInfo(state, encodingOptions, liveStreamResponse.MediaSource, state.RequestedUrl); - if (state.VideoRequest != null) + if (state.VideoRequest is not null) { _encodingHelper.TryStreamCopy(state); } @@ -829,7 +823,7 @@ namespace Jellyfin.Api.Helpers { var job = _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && string.Equals(j.Path, path, StringComparison.OrdinalIgnoreCase)); - if (job == null) + if (job is null) { return null; } |
