fix: player MaxBitRate cap, format-aware defaults, browser profile filtering (#5165)
* feat(transcode): apply player MaxBitRate cap and use format-aware default bitrates Add player MaxBitRate cap to the transcode decider so server-side player bitrate limits are respected when making OpenSubsonic transcode decisions. The player cap is applied only when it is more restrictive than the client's maxAudioBitrate (or when the client has no limit). Also replace the hardcoded 256 kbps default with a format-aware lookup that checks the DB first (for user-customized values), then built-in defaults, and finally falls back to 256 kbps. For lossless→lossy transcoding, prefer maxTranscodingAudioBitrate over maxAudioBitrate when available. * test(e2e): add tests for player MaxBitRate cap and format-aware default bitrates Add e2e tests covering: - Player MaxBitRate forcing transcode when source exceeds cap - Player MaxBitRate having no effect when source is under cap - Client limit winning when more restrictive than player MaxBitRate - Player MaxBitRate winning when more restrictive than client limit - Player MaxBitRate=0 having no effect - Format-aware defaults: mp3 (192kbps), opus (128kbps) instead of hardcoded 256 - maxAudioBitrate fallback for lossless→lossy when no maxTranscodingAudioBitrate - maxTranscodingAudioBitrate taking priority over maxAudioBitrate - Combined player + client limits flowing correctly through decision→stream * feat(transcode): update transcoding profiles to add flac, filter by supported codecs, and ensure mp3 fallback Signed-off-by: Deluan <deluan@navidrome.org> * fix(db): ensure all default transcodings exist on upgrade Older installations that were seeded before aac/flac were added to DefaultTranscodings may be missing these entries. The previous migration only added flac; this one ensures all default transcodings are present without touching user-customized entries. * test: remove duplication Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -9,32 +9,44 @@ export const CODEC_PROBES = [
|
||||
{ codec: 'alac', container: 'mp4', mime: 'audio/mp4; codecs="alac"' },
|
||||
]
|
||||
|
||||
// Default transcoding targets — ordered by preference.
|
||||
// These are attempted if direct play is not possible.
|
||||
const DEFAULT_TRANSCODING_PROFILES = [
|
||||
{ container: 'ogg', audioCodec: 'opus', protocol: 'http' },
|
||||
{ container: 'mp3', audioCodec: 'mp3', protocol: 'http' },
|
||||
]
|
||||
// Transcoding targets in preference order (lossless first, then lossy).
|
||||
// Derived from CODEC_PROBES to avoid duplicating MIME strings.
|
||||
// MP3 is always included as a universal fallback.
|
||||
const TRANSCODE_CODECS = ['flac', 'opus', 'mp3']
|
||||
|
||||
function probeSupported(audio, probes) {
|
||||
return probes.filter(({ mime }) => audio.canPlayType(mime) === 'probably')
|
||||
}
|
||||
|
||||
export function detectBrowserProfile() {
|
||||
const audio = new Audio()
|
||||
const directPlayProfiles = []
|
||||
|
||||
for (const { codec, container, mime } of CODEC_PROBES) {
|
||||
if (audio.canPlayType(mime) === 'probably') {
|
||||
directPlayProfiles.push({
|
||||
containers: [container],
|
||||
audioCodecs: [codec],
|
||||
protocols: ['http'],
|
||||
const directPlayProfiles = probeSupported(audio, CODEC_PROBES).map(
|
||||
({ codec, container }) => ({
|
||||
containers: [container],
|
||||
audioCodecs: [codec],
|
||||
protocols: ['http'],
|
||||
}),
|
||||
)
|
||||
|
||||
// Build transcoding profiles from supported codecs, always keeping mp3 as fallback
|
||||
const transcodingProfiles = TRANSCODE_CODECS.reduce((profiles, codec) => {
|
||||
const probe = CODEC_PROBES.find((p) => p.codec === codec)
|
||||
if (audio.canPlayType(probe.mime) === 'probably' || codec === 'mp3') {
|
||||
profiles.push({
|
||||
container: probe.container,
|
||||
audioCodec: codec,
|
||||
protocol: 'http',
|
||||
})
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}, [])
|
||||
|
||||
return {
|
||||
name: 'NavidromeUI',
|
||||
platform: navigator.userAgent,
|
||||
directPlayProfiles,
|
||||
transcodingProfiles: DEFAULT_TRANSCODING_PROFILES,
|
||||
transcodingProfiles,
|
||||
codecProfiles: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,14 +54,49 @@ describe('detectBrowserProfile', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('includes transcoding profiles for common formats', () => {
|
||||
it('filters transcoding profiles by canPlayType', () => {
|
||||
mockCanPlayType.mockImplementation((mime) => {
|
||||
if (mime === 'audio/mpeg') return 'probably'
|
||||
if (mime === 'audio/ogg; codecs="opus"') return 'probably'
|
||||
return ''
|
||||
})
|
||||
|
||||
const profile = detectBrowserProfile()
|
||||
const codecs = profile.transcodingProfiles.map((p) => p.audioCodec)
|
||||
expect(codecs).toEqual(['opus', 'mp3'])
|
||||
expect(codecs).not.toContain('flac')
|
||||
profile.transcodingProfiles.forEach((p) => {
|
||||
expect(p.protocol).toBe('http')
|
||||
})
|
||||
})
|
||||
|
||||
it('always includes mp3 fallback in transcoding profiles', () => {
|
||||
mockCanPlayType.mockReturnValue('')
|
||||
|
||||
const profile = detectBrowserProfile()
|
||||
expect(profile.transcodingProfiles.length).toBeGreaterThan(0)
|
||||
expect(profile.transcodingProfiles.length).toBe(1)
|
||||
expect(profile.transcodingProfiles[0].audioCodec).toBe('mp3')
|
||||
expect(profile.transcodingProfiles[0].protocol).toBe('http')
|
||||
})
|
||||
|
||||
it('does not duplicate mp3 when canPlayType supports it', () => {
|
||||
mockCanPlayType.mockReturnValue('probably')
|
||||
|
||||
const profile = detectBrowserProfile()
|
||||
const mp3Count = profile.transcodingProfiles.filter(
|
||||
(p) => p.audioCodec === 'mp3',
|
||||
).length
|
||||
expect(mp3Count).toBe(1)
|
||||
})
|
||||
|
||||
it('preserves transcoding profile preference order', () => {
|
||||
mockCanPlayType.mockReturnValue('probably')
|
||||
|
||||
const profile = detectBrowserProfile()
|
||||
const codecs = profile.transcodingProfiles.map((p) => p.audioCodec)
|
||||
expect(codecs).toEqual(['flac', 'opus', 'mp3'])
|
||||
})
|
||||
|
||||
it('sets codecProfiles to empty array', () => {
|
||||
mockCanPlayType.mockReturnValue('probably')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user