fix(transcoding): honor player forced format on the WebUI transcode flow (#5613)

* feat(stream): add ClientInfo.ForceFormat for browser-aware forced format

Restricts the client to a forced transcoding format and suppresses direct
play, but only when the client declares it supports that format. Part of #5583.

* fix(transcoding): honor player forced format on getTranscodeDecision

When the WebUI player has a forced transcoding format configured and the
browser declares it can play that format, transcode to it (suppressing
direct play). Fall back to normal negotiation with a warning when the
format is unsupported. The MaxBitRate cap still applies on top. Fixes #5583.

* test(e2e): cover player forced format on getTranscodeDecision

Forced format honored when the client supports it, falls back to negotiation
otherwise, and the MaxBitRate cap still applies on top. Part of #5583.

* feat(ui): remove obsolete 'format ignored' helper text on player form

The web player now honors the forced transcoding format, so the caveat added
in #5611 no longer applies. Reverts the Transcoding field to a plain selector.
Part of #5583.
This commit is contained in:
Deluan Quintão 2026-06-14 20:52:19 -04:00 • committed by GitHub
commit 08a027dbcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 234 additions and 86 deletions

View file

@ -305,6 +305,73 @@ var _ = Describe("Transcode endpoints", func() {
Expect(mockTD.capturedClient.MaxAudioBitrate).To(Equal(320))
})
})
Describe("player forced format", func() {
withForcedFormat := func(r *http.Request, format string, maxBitRate int) *http.Request {
ctx := r.Context()
ctx = request.WithTranscoding(ctx, model.Transcoding{TargetFormat: format})
if maxBitRate > 0 {
ctx = request.WithPlayer(ctx, model.Player{Client: "NavidromeUI", MaxBitRate: maxBitRate})
}
return r.WithContext(ctx)
}
BeforeEach(func() {
mockMFRepo.SetData(model.MediaFiles{
{ID: "song-1", Suffix: "flac", Codec: "FLAC", BitRate: 900, Channels: 2, SampleRate: 44100},
})
mockTD.decision = &stream.TranscodeDecision{MediaID: "song-1", CanTranscode: true}
mockTD.token = "token"
})
It("forces a supported format and clears direct play", func() {
body := `{"directPlayProfiles":[{"containers":["flac"],"audioCodecs":["flac"],"protocols":["http"]}],
"transcodingProfiles":[{"container":"ogg","audioCodec":"opus","protocol":"http"},
{"container":"mp3","audioCodec":"mp3","protocol":"http"}]}`
r := withForcedFormat(newJSONPostRequest("mediaId=song-1&mediaType=song", body), "opus", 0)
_, err := router.GetTranscodeDecision(w, r)
Expect(err).ToNot(HaveOccurred())
Expect(mockTD.capturedClient.TranscodingProfiles).To(HaveLen(1))
Expect(mockTD.capturedClient.TranscodingProfiles[0].AudioCodec).To(Equal("opus"))
Expect(mockTD.capturedClient.DirectPlayProfiles).To(BeEmpty())
})
It("falls back to negotiation when the forced format is unsupported", func() {
// Forced format is opus, but the client only declares mp3 and flac.
// Should fall back to negotiating among the client's own profiles.
body := `{"directPlayProfiles":[{"containers":["flac"],"audioCodecs":["flac"],"protocols":["http"]}],
"transcodingProfiles":[
{"container":"flac","audioCodec":"flac","protocol":"http"},
{"container":"mp3","audioCodec":"mp3","protocol":"http"}]}`
r := withForcedFormat(newJSONPostRequest("mediaId=song-1&mediaType=song", body), "opus", 0)
_, err := router.GetTranscodeDecision(w, r)
Expect(err).ToNot(HaveOccurred())
// Profiles left intact for normal negotiation (forced format not applied).
Expect(mockTD.capturedClient.TranscodingProfiles).To(HaveLen(2))
Expect(mockTD.capturedClient.DirectPlayProfiles).ToNot(BeEmpty())
})
It("applies the maxBitRate cap on top of the forced format", func() {
// Client supports opus + mp3; forced format opus must be selected,
// and the maxBitRate cap applied on top.
body := `{"transcodingProfiles":[
{"container":"ogg","audioCodec":"opus","protocol":"http"},
{"container":"mp3","audioCodec":"mp3","protocol":"http"}]}`
r := withForcedFormat(newJSONPostRequest("mediaId=song-1&mediaType=song", body), "opus", 128)
_, err := router.GetTranscodeDecision(w, r)
Expect(err).ToNot(HaveOccurred())
Expect(mockTD.capturedClient.TranscodingProfiles).To(HaveLen(1))
Expect(mockTD.capturedClient.TranscodingProfiles[0].AudioCodec).To(Equal("opus"))
Expect(mockTD.capturedClient.MaxAudioBitrate).To(Equal(128))
Expect(mockTD.capturedClient.MaxTranscodingAudioBitrate).To(Equal(128))
})
})
})
Describe("GetTranscodeStream", func() {