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
2.4 KiB
Go
85 lines
2.4 KiB
Go
package stream
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model"
|
|
)
|
|
|
|
// buildLegacyClientInfo translates legacy Subsonic stream/download parameters
|
|
// into a ClientInfo for use with MakeDecision.
|
|
// It does NOT read request.TranscodingFrom(ctx) — that is handled by
|
|
// MakeDecision's applyServerOverride.
|
|
func buildLegacyClientInfo(mf *model.MediaFile, reqFormat string, reqBitRate int) *ClientInfo {
|
|
ci := &ClientInfo{Name: "legacy"}
|
|
|
|
// Determine target format for transcoding
|
|
var targetFormat string
|
|
switch {
|
|
case reqFormat != "":
|
|
targetFormat = reqFormat
|
|
case reqBitRate > 0 && reqBitRate < mf.BitRate && conf.Server.DefaultDownsamplingFormat != "":
|
|
targetFormat = conf.Server.DefaultDownsamplingFormat
|
|
}
|
|
|
|
if targetFormat != "" {
|
|
ci.DirectPlayProfiles = []DirectPlayProfile{
|
|
{Containers: []string{mf.Suffix}, AudioCodecs: []string{mf.AudioCodec()}, Protocols: []string{ProtocolHTTP}},
|
|
}
|
|
ci.TranscodingProfiles = []Profile{
|
|
{Container: targetFormat, AudioCodec: targetFormat, Protocol: ProtocolHTTP},
|
|
}
|
|
if reqBitRate > 0 {
|
|
ci.MaxAudioBitrate = reqBitRate
|
|
ci.MaxTranscodingAudioBitrate = reqBitRate
|
|
}
|
|
} else {
|
|
// No transcoding requested — direct play everything
|
|
ci.DirectPlayProfiles = []DirectPlayProfile{
|
|
{Protocols: []string{ProtocolHTTP}},
|
|
}
|
|
}
|
|
|
|
return ci
|
|
}
|
|
|
|
// ResolveRequest uses MakeDecision to resolve legacy Subsonic stream parameters
|
|
// into a fully specified Request.
|
|
func (s *deciderService) ResolveRequest(ctx context.Context, mf *model.MediaFile, reqFormat string, reqBitRate int, offset int) Request {
|
|
var req Request
|
|
req.Offset = offset
|
|
|
|
if reqFormat == "raw" {
|
|
req.Format = "raw"
|
|
return req
|
|
}
|
|
|
|
clientInfo := buildLegacyClientInfo(mf, reqFormat, reqBitRate)
|
|
decision, err := s.MakeDecision(ctx, mf, clientInfo, TranscodeOptions{SkipProbe: true})
|
|
if err != nil {
|
|
log.Error(ctx, "Error making transcode decision, falling back to raw", "id", mf.ID, err)
|
|
req.Format = "raw"
|
|
return req
|
|
}
|
|
|
|
if decision.CanDirectPlay {
|
|
req.Format = "raw"
|
|
return req
|
|
}
|
|
|
|
if decision.CanTranscode {
|
|
req.Format = decision.TargetFormat
|
|
req.BitRate = decision.TargetBitrate
|
|
req.SampleRate = decision.TargetSampleRate
|
|
req.BitDepth = decision.TargetBitDepth
|
|
req.Channels = decision.TargetChannels
|
|
return req
|
|
}
|
|
|
|
// No compatible profile — fallback to raw
|
|
req.Format = "raw"
|
|
return req
|
|
}
|