2024-07-02 07:44:37 +03:00
|
|
|
package handlers
|
2021-03-11 23:51:43 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
"github.com/owncast/owncast/persistence/configrepository"
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils "github.com/owncast/owncast/webserver/utils"
|
2021-03-11 23:51:43 +03:00
|
|
|
)
|
|
|
|
|
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) {
|
2024-11-16 06:20:58 +03:00
|
|
|
configRepository := configrepository.Get()
|
|
|
|
outputVariants := configRepository.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
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteResponse(w, response)
|
2021-03-11 23:51:43 +03:00
|
|
|
}
|