Allow selection of different stream variants in the player (#815)

* 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
This commit is contained in:
Gabe Kangas
2021-03-11 12:51:43 -08:00
committed by GitHub
parent 145744c381
commit c713e216d3
7 changed files with 185 additions and 4 deletions

45
controllers/video.go Normal file
View File

@@ -0,0 +1,45 @@
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)
}