mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
34 lines
842 B
Go
34 lines
842 B
Go
package config
|
|
|
|
import "sort"
|
|
|
|
func findHighestQuality(qualities []StreamQuality) int {
|
|
type IndexedQuality struct {
|
|
index int
|
|
quality StreamQuality
|
|
}
|
|
|
|
if len(qualities) < 2 {
|
|
return 0
|
|
}
|
|
|
|
indexedQualities := make([]IndexedQuality, 0)
|
|
for index, quality := range qualities {
|
|
indexedQuality := IndexedQuality{index, quality}
|
|
indexedQualities = append(indexedQualities, indexedQuality)
|
|
}
|
|
|
|
sort.Slice(indexedQualities, func(a, b int) bool {
|
|
if indexedQualities[a].quality.IsVideoPassthrough && !indexedQualities[b].quality.IsVideoPassthrough {
|
|
return true
|
|
}
|
|
|
|
if !indexedQualities[a].quality.IsVideoPassthrough && indexedQualities[b].quality.IsVideoPassthrough {
|
|
return false
|
|
}
|
|
|
|
return indexedQualities[a].quality.VideoBitrate > indexedQualities[b].quality.VideoBitrate
|
|
})
|
|
|
|
return indexedQualities[0].index
|
|
}
|