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:
45
controllers/video.go
Normal file
45
controllers/video.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user