🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Don't try to downsample if requested bitrate is equal or greater than original. Fix #2066
Deluan127c75e34b50
diff --git a/core/media_streamer.go b/core/media_streamer.goindex 2a13233c2..0b3203dac 100644--- a/core/media_streamer.go+++ b/core/media_streamer.go@@ -147,8 +147,10 @@ func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *modelif p, ok := request.PlayerFrom(ctx); ok {cBitRate = p.MaxBitRate}- } else if reqBitRate > 0 && conf.Server.DefaultDownsamplingFormat != "" {- // If no format is specified and no transcoding associated to the player, but a bitrate is specfied, and there is no transcoding set for the player, we use the default downsampling format+ } else if reqBitRate > 0 && reqBitRate < mf.BitRate && conf.Server.DefaultDownsamplingFormat != "" {+ // If no format is specified and no transcoding associated to the player, but a bitrate is specified,+ // and there is no transcoding set for the player, we use the default downsampling format.+ // But only if the requested bitRate is lower than the original bitRate.log.Debug("Default Downsampling", "Using default downsampling format", conf.Server.DefaultDownsamplingFormat)cFormat = conf.Server.DefaultDownsamplingFormat}diff --git a/core/media_streamer_Internal_test.go b/core/media_streamer_Internal_test.goindex 52ad82393..06947869b 100644--- a/core/media_streamer_Internal_test.go+++ b/core/media_streamer_Internal_test.go@@ -75,14 +75,23 @@ var _ = Describe("MediaStreamer", func() {Expect(format).To(Equal("raw"))Expect(bitRate).To(Equal(320))})- It("returns the DefaultDownsamplingFormat if a maxBitrate but not the format", func() {- conf.Server.DefaultDownsamplingFormat = "opus"- mf.Suffix = "FLAC"- mf.BitRate = 960- format, bitRate := selectTranscodingOptions(ctx, ds, mf, "", 128)- Expect(format).To(Equal("opus"))- Expect(bitRate).To(Equal(128))-+ Context("Downsampling", func() {+ BeforeEach(func() {+ conf.Server.DefaultDownsamplingFormat = "opus"+ mf.Suffix = "FLAC"+ mf.BitRate = 960+ })+ It("returns the DefaultDownsamplingFormat if a maxBitrate is requested but not the format", func() {+ format, bitRate := selectTranscodingOptions(ctx, ds, mf, "", 128)+ Expect(format).To(Equal("opus"))+ Expect(bitRate).To(Equal(128))+ })+ It("returns raw if maxBitrate is equal or greater than original", func() {+ // This happens with DSub (and maybe other clients?). See https://github.com/navidrome/navidrome/issues/2066+ format, bitRate := selectTranscodingOptions(ctx, ds, mf, "", 960)+ Expect(format).To(Equal("raw"))+ Expect(bitRate).To(Equal(0))+ })})})