Don't try to downsample if requested bitrate is equal or greater than original. Fix #2066

This commit is contained in:
Deluan 2023-01-18 13:20:51 -05:00
parent d5c9cf07bd
commit 127c75e34b
2 changed files with 21 additions and 10 deletions

View File

@ -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
}

View File

@ -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))
})
})
})