owncast/controllers/video.go
Gabe Kangas 85e7af3d5f
Update to Go 1.20 + run better align (#2927)
* chore(go): update go version to 1.20. Closes #2185

* chore(go): run better align against project

To optimize struct field order. Closes #2870

* chore(go): update CI jobs to use Go 1.20

* fix(go): linter warnings for Go 1.20 update
2023-05-30 10:31:43 -07:00

59 lines
1.5 KiB
Go

package controllers
import (
"net/http"
"sort"
"github.com/owncast/owncast/core/data"
)
type variantsSort struct {
Name string
Index int
VideoBitrate int
IsVideoPassthrough bool
}
type variantsResponse struct {
Name string `json:"name"`
Index int `json:"index"`
}
// GetVideoStreamOutputVariants will return the video variants available.
func GetVideoStreamOutputVariants(w http.ResponseWriter, r *http.Request) {
outputVariants := data.GetStreamOutputVariants()
streamSortVariants := make([]variantsSort, len(outputVariants))
for i, variant := range outputVariants {
variantSort := variantsSort{
Index: i,
Name: variant.GetName(),
IsVideoPassthrough: variant.IsVideoPassthrough,
VideoBitrate: variant.VideoBitrate,
}
streamSortVariants[i] = variantSort
}
sort.Slice(streamSortVariants, func(i, j int) bool {
if streamSortVariants[i].IsVideoPassthrough && !streamSortVariants[j].IsVideoPassthrough {
return true
}
if !streamSortVariants[i].IsVideoPassthrough && streamSortVariants[j].IsVideoPassthrough {
return false
}
return streamSortVariants[i].VideoBitrate > streamSortVariants[j].VideoBitrate
})
response := make([]variantsResponse, len(streamSortVariants))
for i, variant := range streamSortVariants {
variantResponse := variantsResponse{
Index: variant.Index,
Name: variant.Name,
}
response[i] = variantResponse
}
WriteResponse(w, response)
}