c713e216d3
* WIP video quality selector * The quality selector works even though it is not pretty * Support getting and setting variant name. Closes #743 * Sort video qualities * Fix odd looking selected states of menubutton items * Fix comment
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
"sort"
|
|
|
|
"github.com/owncast/owncast/core/data"
|
|
"github.com/owncast/owncast/models"
|
|
)
|
|
|
|
type variants []models.StreamOutputVariant
|
|
|
|
type variantsResponse struct {
|
|
Name string `json:"name"`
|
|
Index int `json:"index"`
|
|
}
|
|
|
|
// Len returns the number of variants.
|
|
func (v variants) Len() int { return len(v) }
|
|
|
|
// Less is less than..
|
|
func (v variants) Less(i, j int) bool { return v[i].VideoBitrate < v[j].VideoBitrate }
|
|
|
|
// Swap will swap two values.
|
|
func (v variants) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
|
|
|
// GetVideoStreamOutputVariants will return the video variants available,
|
|
func GetVideoStreamOutputVariants(w http.ResponseWriter, r *http.Request) {
|
|
outputVariants := data.GetStreamOutputVariants()
|
|
result := make([]variantsResponse, len(outputVariants))
|
|
|
|
for i, variant := range outputVariants {
|
|
variantResponse := variantsResponse{
|
|
Index: i,
|
|
Name: variant.GetName(),
|
|
}
|
|
result[i] = variantResponse
|
|
}
|
|
|
|
sort.Slice(result, func(i, j int) bool {
|
|
return outputVariants[i].VideoBitrate > outputVariants[j].VideoBitrate || !outputVariants[i].IsVideoPassthrough
|
|
})
|
|
|
|
WriteResponse(w, result)
|
|
}
|