From 127c75e34b5052872590f7fd508125b327a7201e Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 18 Jan 2023 13:20:51 -0500 Subject: [PATCH] Don't try to downsample if requested bitrate is equal or greater than original. Fix #2066 --- core/media_streamer.go | 6 ++++-- core/media_streamer_Internal_test.go | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/media_streamer.go b/core/media_streamer.go index 2a13233c..0b3203da 100644 --- a/core/media_streamer.go +++ b/core/media_streamer.go @@ -147,8 +147,10 @@ func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *model if 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.go index 52ad8239..06947869 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)) + }) }) })