apply best resolution from non HLS to HLS stream

This makes sure that HLS Streams can be compared with non HLS streams, otherwise HLS would have been the first selected since the maxResolution.value might have been higher then what could actually be the highest resolution served.
This commit is contained in:
Toni Förster 2024-05-11 14:08:40 +02:00
parent d8c8f8084b
commit fba01e35a3
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7

View File

@ -131,9 +131,17 @@ extension PlayerBackend {
} }
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting, formatOrder: [QualityProfile.Format]) -> Stream? { func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting, formatOrder: [QualityProfile.Format]) -> Stream? {
// filter out non HLS streams
let nonHLSStreams = streams.filter { $0.kind != .hls }
// find max resolution from non HLS streams
let bestResolution = nonHLSStreams
.filter { $0.resolution <= maxResolution.value }
.max { $0.resolution < $1.resolution }?.resolution
return streams.map { stream in return streams.map { stream in
if stream.kind == .hls { if stream.kind == .hls {
stream.resolution = maxResolution.value stream.resolution = bestResolution ?? maxResolution.value
stream.format = .hls stream.format = .hls
} else if stream.kind == .stream { } else if stream.kind == .stream {
stream.format = .stream stream.format = .stream