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