Procházet zdrojové kódy

Merge pull request #8546 from nyanmisaka/fix-fmp4-flac-opus

Cody Robibero před 2 roky
rodič
revize
bf3ff15843

+ 40 - 2
Jellyfin.Api/Helpers/DynamicHlsHelper.cs

@@ -197,6 +197,13 @@ namespace Jellyfin.Api.Helpers
 
 
             if (state.VideoStream != null && state.VideoRequest != null)
             if (state.VideoStream != null && state.VideoRequest != 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.
                 // Provide SDR HEVC entrance for backward compatibility.
                 if (EncodingHelper.IsCopyCodec(state.OutputVideoCodec)
                 if (EncodingHelper.IsCopyCodec(state.OutputVideoCodec)
                     && !string.IsNullOrEmpty(state.VideoStream.VideoRange)
                     && !string.IsNullOrEmpty(state.VideoStream.VideoRange)
@@ -215,7 +222,14 @@ namespace Jellyfin.Api.Helpers
                         var sdrOutputAudioBitrate = _encodingHelper.GetAudioBitrateParam(state.VideoRequest, state.AudioStream) ?? 0;
                         var sdrOutputAudioBitrate = _encodingHelper.GetAudioBitrateParam(state.VideoRequest, state.AudioStream) ?? 0;
                         var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate;
                         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
                         // Restore the video codec
                         state.OutputVideoCodec = "copy";
                         state.OutputVideoCodec = "copy";
@@ -245,6 +259,13 @@ namespace Jellyfin.Api.Helpers
                     state.VideoStream.Level = originalLevel;
                     state.VideoStream.Level = originalLevel;
                     var newPlaylist = ReplacePlaylistCodecsField(basicPlaylist, playlistCodecsField, newPlaylistCodecsField);
                     var newPlaylist = ReplacePlaylistCodecsField(basicPlaylist, playlistCodecsField, newPlaylistCodecsField);
                     builder.Append(newPlaylist);
                     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);
+                    }
                 }
                 }
             }
             }
 
 
@@ -603,6 +624,11 @@ namespace Jellyfin.Api.Helpers
                 return HlsCodecStringHelpers.GetALACString();
                 return HlsCodecStringHelpers.GetALACString();
             }
             }
 
 
+            if (string.Equals(state.ActualOutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase))
+            {
+                return HlsCodecStringHelpers.GetOPUSString();
+            }
+
             return string.Empty;
             return string.Empty;
         }
         }
 
 
@@ -701,7 +727,19 @@ namespace Jellyfin.Api.Helpers
             return oldPlaylist.Replace(
             return oldPlaylist.Replace(
                 oldValue.ToString(),
                 oldValue.ToString(),
                 newValue.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;
         }
         }
     }
     }
 }
 }

+ 15 - 1
Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs

@@ -27,13 +27,18 @@ namespace Jellyfin.Api.Helpers
         /// <summary>
         /// <summary>
         /// Codec name for FLAC.
         /// Codec name for FLAC.
         /// </summary>
         /// </summary>
-        public const string FLAC = "fLaC";
+        public const string FLAC = "flac";
 
 
         /// <summary>
         /// <summary>
         /// Codec name for ALAC.
         /// Codec name for ALAC.
         /// </summary>
         /// </summary>
         public const string ALAC = "alac";
         public const string ALAC = "alac";
 
 
+        /// <summary>
+        /// Codec name for OPUS.
+        /// </summary>
+        public const string OPUS = "opus";
+
         /// <summary>
         /// <summary>
         /// Gets a MP3 codec string.
         /// Gets a MP3 codec string.
         /// </summary>
         /// </summary>
@@ -101,6 +106,15 @@ namespace Jellyfin.Api.Helpers
             return ALAC;
             return ALAC;
         }
         }
 
 
+        /// <summary>
+        /// Gets an OPUS codec string.
+        /// </summary>
+        /// <returns>OPUS codec string.</returns>
+        public static string GetOPUSString()
+        {
+            return OPUS;
+        }
+
         /// <summary>
         /// <summary>
         /// Gets a H.264 codec string.
         /// Gets a H.264 codec string.
         /// </summary>
         /// </summary>