767744a301
* refactor: rename core/transcode directory to core/stream * refactor: update all imports from core/transcode to core/stream * refactor: rename exported symbols to fit core/stream package name * refactor: simplify MediaStreamer interface to single NewStream method Remove the two-method interface (NewStream + DoStream) in favor of a single NewStream(ctx, mf, req) method. Callers are now responsible for fetching the MediaFile before calling NewStream. This removes the implicit DB lookup from the streamer, making it a pure streaming concern. * refactor: update all callers from DoStream to NewStream * chore: update wire_gen.go and stale comment for core/stream rename * refactor: update wire command to handle GO_BUILD_TAGS correctly Signed-off-by: Deluan <deluan@navidrome.org> * fix: distinguish not-found from internal errors in public stream handler * refactor: remove unused ID field from stream.Request * refactor: simplify ResolveRequestFromToken to receive *model.MediaFile Move MediaFile fetching responsibility to callers, making the method focused on token validation and request resolution. Remove ErrMediaNotFound (no longer produced). Update GetTranscodeStream handler to fetch the media file before calling ResolveRequestFromToken. * refactor: extend tokenTTL from 12 to 48 hours Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
85 lines
3.3 KiB
Go
85 lines
3.3 KiB
Go
package stream
|
|
|
|
import (
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/conf/configtest"
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("buildLegacyClientInfo", func() {
|
|
var mf *model.MediaFile
|
|
|
|
BeforeEach(func() {
|
|
mf = &model.MediaFile{Suffix: "flac", BitRate: 960}
|
|
})
|
|
|
|
It("sets transcoding profile for explicit format without bitrate", func() {
|
|
ci := buildLegacyClientInfo(mf, "mp3", 0)
|
|
|
|
Expect(ci.Name).To(Equal("legacy"))
|
|
Expect(ci.TranscodingProfiles).To(HaveLen(1))
|
|
Expect(ci.TranscodingProfiles[0].Container).To(Equal("mp3"))
|
|
Expect(ci.TranscodingProfiles[0].AudioCodec).To(Equal("mp3"))
|
|
Expect(ci.TranscodingProfiles[0].Protocol).To(Equal(ProtocolHTTP))
|
|
Expect(ci.MaxAudioBitrate).To(BeZero())
|
|
Expect(ci.MaxTranscodingAudioBitrate).To(BeZero())
|
|
Expect(ci.DirectPlayProfiles).To(HaveLen(1))
|
|
Expect(ci.DirectPlayProfiles[0].Containers).To(Equal([]string{"flac"}))
|
|
Expect(ci.DirectPlayProfiles[0].AudioCodecs).To(Equal([]string{mf.AudioCodec()}))
|
|
Expect(ci.DirectPlayProfiles[0].Protocols).To(Equal([]string{ProtocolHTTP}))
|
|
})
|
|
|
|
It("sets transcoding profile and bitrate for explicit format with bitrate", func() {
|
|
ci := buildLegacyClientInfo(mf, "mp3", 192)
|
|
|
|
Expect(ci.TranscodingProfiles).To(HaveLen(1))
|
|
Expect(ci.TranscodingProfiles[0].Container).To(Equal("mp3"))
|
|
Expect(ci.TranscodingProfiles[0].AudioCodec).To(Equal("mp3"))
|
|
Expect(ci.MaxAudioBitrate).To(Equal(192))
|
|
Expect(ci.MaxTranscodingAudioBitrate).To(Equal(192))
|
|
Expect(ci.DirectPlayProfiles).To(HaveLen(1))
|
|
Expect(ci.DirectPlayProfiles[0].Containers).To(Equal([]string{"flac"}))
|
|
})
|
|
|
|
It("returns direct play profile when no format and no bitrate", func() {
|
|
ci := buildLegacyClientInfo(mf, "", 0)
|
|
|
|
Expect(ci.DirectPlayProfiles).To(HaveLen(1))
|
|
Expect(ci.DirectPlayProfiles[0].Containers).To(BeEmpty())
|
|
Expect(ci.DirectPlayProfiles[0].AudioCodecs).To(BeEmpty())
|
|
Expect(ci.DirectPlayProfiles[0].Protocols).To(Equal([]string{ProtocolHTTP}))
|
|
Expect(ci.TranscodingProfiles).To(BeEmpty())
|
|
Expect(ci.MaxAudioBitrate).To(BeZero())
|
|
})
|
|
|
|
It("uses default downsampling format for bitrate-only downsampling", func() {
|
|
DeferCleanup(configtest.SetupConfig())
|
|
conf.Server.DefaultDownsamplingFormat = "opus"
|
|
|
|
ci := buildLegacyClientInfo(mf, "", 128)
|
|
|
|
Expect(ci.TranscodingProfiles).To(HaveLen(1))
|
|
Expect(ci.TranscodingProfiles[0].Container).To(Equal("opus"))
|
|
Expect(ci.TranscodingProfiles[0].AudioCodec).To(Equal("opus"))
|
|
Expect(ci.TranscodingProfiles[0].Protocol).To(Equal(ProtocolHTTP))
|
|
Expect(ci.MaxAudioBitrate).To(Equal(128))
|
|
Expect(ci.MaxTranscodingAudioBitrate).To(Equal(128))
|
|
Expect(ci.DirectPlayProfiles).To(HaveLen(1))
|
|
Expect(ci.DirectPlayProfiles[0].Containers).To(Equal([]string{"flac"}))
|
|
Expect(ci.DirectPlayProfiles[0].AudioCodecs).To(Equal([]string{mf.AudioCodec()}))
|
|
})
|
|
|
|
It("returns direct play when bitrate >= source bitrate", func() {
|
|
ci := buildLegacyClientInfo(mf, "", 960)
|
|
|
|
Expect(ci.DirectPlayProfiles).To(HaveLen(1))
|
|
Expect(ci.DirectPlayProfiles[0].Containers).To(BeEmpty())
|
|
Expect(ci.DirectPlayProfiles[0].AudioCodecs).To(BeEmpty())
|
|
Expect(ci.DirectPlayProfiles[0].Protocols).To(Equal([]string{ProtocolHTTP}))
|
|
Expect(ci.TranscodingProfiles).To(BeEmpty())
|
|
Expect(ci.MaxAudioBitrate).To(BeZero())
|
|
})
|
|
})
|