2021-03-11 23:51:43 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/core/data"
|
|
|
|
)
|
|
|
|
|
2021-08-04 21:34:02 +03:00
|
|
|
type variantsSort struct {
|
|
|
|
Name string
|
2023-05-30 20:31:43 +03:00
|
|
|
Index int
|
2021-08-04 21:34:02 +03:00
|
|
|
VideoBitrate int
|
2023-05-30 20:31:43 +03:00
|
|
|
IsVideoPassthrough bool
|
2021-08-04 21:34:02 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 23:51:43 +03:00
|
|
|
type variantsResponse struct {
|
2021-08-04 21:34:02 +03:00
|
|
|
Name string `json:"name"`
|
2023-05-30 20:31:43 +03:00
|
|
|
Index int `json:"index"`
|
2021-03-11 23:51:43 +03:00
|
|
|
}
|
|
|
|
|
2021-06-29 20:21:00 +03:00
|
|
|
// GetVideoStreamOutputVariants will return the video variants available.
|
2021-03-11 23:51:43 +03:00
|
|
|
func GetVideoStreamOutputVariants(w http.ResponseWriter, r *http.Request) {
|
|
|
|
outputVariants := data.GetStreamOutputVariants()
|
2021-07-02 04:17:50 +03:00
|
|
|
|
2021-08-04 21:34:02 +03:00
|
|
|
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
|
|
|
|
}
|
2021-07-02 04:17:50 +03:00
|
|
|
|
2021-08-04 21:34:02 +03:00
|
|
|
sort.Slice(streamSortVariants, func(i, j int) bool {
|
|
|
|
if streamSortVariants[i].IsVideoPassthrough && !streamSortVariants[j].IsVideoPassthrough {
|
|
|
|
return true
|
|
|
|
}
|
2021-03-11 23:51:43 +03:00
|
|
|
|
2021-08-04 21:34:02 +03:00
|
|
|
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 {
|
2021-03-11 23:51:43 +03:00
|
|
|
variantResponse := variantsResponse{
|
2021-08-04 21:34:02 +03:00
|
|
|
Index: variant.Index,
|
|
|
|
Name: variant.Name,
|
2021-03-11 23:51:43 +03:00
|
|
|
}
|
2021-08-04 21:34:02 +03:00
|
|
|
response[i] = variantResponse
|
2021-03-11 23:51:43 +03:00
|
|
|
}
|
|
|
|
|
2021-08-04 21:34:02 +03:00
|
|
|
WriteResponse(w, response)
|
2021-03-11 23:51:43 +03:00
|
|
|
}
|