From e9f23c61c937b230b1d3bd7865a083aeb3d51657 Mon Sep 17 00:00:00 2001 From: Jan Müller Date: Tue, 1 Aug 2023 17:11:32 +0200 Subject: Fix the fLaC/flac HLS issue also for audio-only I moved the first application of the workaround out of the if block so that it also applies to audio-only streams. The workaround was extended likewise. We should first and foremost adhere to the specifications and apply workarounds afterwards for software that doesn't follow them. So I turned around the workaround to first output the fLaC variant and then the alternative flac variant. Fixes: #10066 --- Jellyfin.Api/Helpers/DynamicHlsHelper.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'Jellyfin.Api/Helpers/DynamicHlsHelper.cs') diff --git a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs index 63667e7e6..dfcccddfc 100644 --- a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs +++ b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs @@ -198,15 +198,15 @@ public class DynamicHlsHelper var basicPlaylist = AppendPlaylist(builder, state, playlistUrl, totalBitrate, subtitleGroup); - 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)) { - // Provide a workaround for the case issue between flac and fLaC. - var flacWaPlaylist = ApplyFlacCaseWorkaround(state, basicPlaylist.ToString()); - if (!string.IsNullOrEmpty(flacWaPlaylist)) - { - builder.Append(flacWaPlaylist); - } + builder.Append(flacWaPlaylist); + } + if (state.VideoStream is not null && state.VideoRequest is not null) + { var encodingOptions = _serverConfigurationManager.GetEncodingOptions(); // Provide SDR HEVC entrance for backward compatibility. @@ -775,8 +775,11 @@ public class DynamicHlsHelper return string.Empty; } - var newPlaylist = srcPlaylist.Replace(",flac\"", ",fLaC\"", StringComparison.Ordinal); + var newPlaylist = srcPlaylist; + + newPlaylist = newPlaylist.Replace(",fLaC\"", ",flac\"", StringComparison.Ordinal); + newPlaylist = newPlaylist.Replace("\"fLaC\"", "\"flac\"", StringComparison.Ordinal); - return newPlaylist.Contains(",fLaC\"", StringComparison.Ordinal) ? newPlaylist : string.Empty; + return string.Equals(srcPlaylist, newPlaylist, StringComparison.Ordinal) ? string.Empty : newPlaylist; } } -- cgit v1.2.3 From 19fb061381dd107d5e0236cf9d8b59b2e2318130 Mon Sep 17 00:00:00 2001 From: Jan Müller Date: Tue, 1 Aug 2023 17:22:42 +0200 Subject: Correct the HLS Opus codec string Apple doesn't support Opus via HLS yet, but if they ever do, they will definitely expect "Opus" instead of "opus". See https://mp4ra.org/#/codecs Fixes: #10066 --- Jellyfin.Api/Helpers/DynamicHlsHelper.cs | 28 ++++++++++++++------------- Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'Jellyfin.Api/Helpers/DynamicHlsHelper.cs') diff --git a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs index dfcccddfc..888b667a6 100644 --- a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs +++ b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs @@ -198,11 +198,11 @@ public class DynamicHlsHelper var basicPlaylist = AppendPlaylist(builder, state, playlistUrl, totalBitrate, subtitleGroup); - // Provide a workaround for the case issue between flac and fLaC. - var flacWaPlaylist = ApplyFlacCaseWorkaround(state, basicPlaylist.ToString()); - if (!string.IsNullOrEmpty(flacWaPlaylist)) + // Provide a workaround for alternative codec string capitalization. + var alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, basicPlaylist.ToString()); + if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) { - builder.Append(flacWaPlaylist); + builder.Append(alternativeCodecCapitalizationPlaylist); } if (state.VideoStream is not null && state.VideoRequest is not null) @@ -238,11 +238,11 @@ public class DynamicHlsHelper var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate; 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)) + // Provide a workaround for alternative codec string capitalization. + alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, sdrPlaylist.ToString()); + if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) { - builder.Append(flacWaPlaylist); + builder.Append(alternativeCodecCapitalizationPlaylist); } // Restore the video codec @@ -275,11 +275,11 @@ public class DynamicHlsHelper 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)) + // Provide a workaround for alternative codec string capitalization. + alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, newPlaylist); + if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) { - builder.Append(flacWaPlaylist); + builder.Append(alternativeCodecCapitalizationPlaylist); } } } @@ -768,7 +768,7 @@ public class DynamicHlsHelper StringComparison.Ordinal); } - private string ApplyFlacCaseWorkaround(StreamState state, string srcPlaylist) + private string ApplyCodecCapitalizationWorkaround(StreamState state, string srcPlaylist) { if (!string.Equals(state.ActualOutputAudioCodec, "flac", StringComparison.OrdinalIgnoreCase)) { @@ -779,6 +779,8 @@ public class DynamicHlsHelper newPlaylist = newPlaylist.Replace(",fLaC\"", ",flac\"", StringComparison.Ordinal); newPlaylist = newPlaylist.Replace("\"fLaC\"", "\"flac\"", StringComparison.Ordinal); + newPlaylist = newPlaylist.Replace(",Opus\"", ",opus\"", StringComparison.Ordinal); + newPlaylist = newPlaylist.Replace("\"Opus\"", "\"opus\"", StringComparison.Ordinal); return string.Equals(srcPlaylist, newPlaylist, StringComparison.Ordinal) ? string.Empty : newPlaylist; } diff --git a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs index 9b1c52045..5eec1b0ca 100644 --- a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs +++ b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs @@ -39,7 +39,7 @@ public static class HlsCodecStringHelpers /// /// Codec name for OPUS. /// - public const string OPUS = "opus"; + public const string OPUS = "Opus"; /// /// Gets a MP3 codec string. -- cgit v1.2.3 From 1635d82345a035c007daffe980cc09de17984813 Mon Sep 17 00:00:00 2001 From: Jan Müller Date: Sat, 16 Sep 2023 12:57:20 +0200 Subject: Remove workaround for codec capitalization This is not required anymore as Shaka Player now supports the correct codec strings. --- Jellyfin.Api/Helpers/DynamicHlsHelper.cs | 40 +------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'Jellyfin.Api/Helpers/DynamicHlsHelper.cs') diff --git a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs index 03b723ef1..276a09f41 100644 --- a/Jellyfin.Api/Helpers/DynamicHlsHelper.cs +++ b/Jellyfin.Api/Helpers/DynamicHlsHelper.cs @@ -198,13 +198,6 @@ public class DynamicHlsHelper var basicPlaylist = AppendPlaylist(builder, state, playlistUrl, totalBitrate, subtitleGroup); - // Provide a workaround for alternative codec string capitalization. - var alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, basicPlaylist.ToString()); - if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) - { - builder.Append(alternativeCodecCapitalizationPlaylist); - } - if (state.VideoStream is not null && state.VideoRequest is not null) { var encodingOptions = _serverConfigurationManager.GetEncodingOptions(); @@ -236,14 +229,7 @@ public class DynamicHlsHelper } var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate; - var sdrPlaylist = AppendPlaylist(builder, state, sdrVideoUrl, sdrTotalBitrate, subtitleGroup); - - // Provide a workaround for alternative codec string capitalization. - alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, sdrPlaylist.ToString()); - if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) - { - builder.Append(alternativeCodecCapitalizationPlaylist); - } + AppendPlaylist(builder, state, sdrVideoUrl, sdrTotalBitrate, subtitleGroup); // Restore the video codec state.OutputVideoCodec = "copy"; @@ -274,13 +260,6 @@ public class DynamicHlsHelper state.VideoStream.Level = originalLevel; var newPlaylist = ReplacePlaylistCodecsField(basicPlaylist, playlistCodecsField, newPlaylistCodecsField); builder.Append(newPlaylist); - - // Provide a workaround for alternative codec string capitalization. - alternativeCodecCapitalizationPlaylist = ApplyCodecCapitalizationWorkaround(state, newPlaylist); - if (!string.IsNullOrEmpty(alternativeCodecCapitalizationPlaylist)) - { - builder.Append(alternativeCodecCapitalizationPlaylist); - } } } @@ -767,21 +746,4 @@ public class DynamicHlsHelper newValue.ToString(), StringComparison.Ordinal); } - - private string ApplyCodecCapitalizationWorkaround(StreamState state, string srcPlaylist) - { - if (!string.Equals(state.ActualOutputAudioCodec, "flac", StringComparison.OrdinalIgnoreCase)) - { - return string.Empty; - } - - var newPlaylist = srcPlaylist; - - newPlaylist = newPlaylist.Replace(",fLaC\"", ",flac\"", StringComparison.Ordinal); - newPlaylist = newPlaylist.Replace("\"fLaC\"", "\"flac\"", StringComparison.Ordinal); - newPlaylist = newPlaylist.Replace(",Opus\"", ",opus\"", StringComparison.Ordinal); - newPlaylist = newPlaylist.Replace("\"Opus\"", "\"opus\"", StringComparison.Ordinal); - - return string.Equals(srcPlaylist, newPlaylist, StringComparison.Ordinal) ? string.Empty : newPlaylist; - } } -- cgit v1.2.3