init
This commit is contained in:
commit
fa47df6d89
22 changed files with 1724 additions and 0 deletions
57
handlersPreset.go
Normal file
57
handlersPreset.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"stream-poc2/ffmpeg"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// The reason why preset is configured separately is that there is no way of representing it properly in the
|
||||
// HLS master/variant playlist which would confuse players, because there would be two identical looking playlist
|
||||
// (hls.js solves this by omitting one for example)
|
||||
// But that's not the only reason. I believe this must be a server-side setting, that the administrators of the server control
|
||||
// So for example, when the server is under high load, they can tune it to "fast" to ease the load, and when there is less demand they can tune it to "slow" for better quality.
|
||||
|
||||
var currentPreset atomic.Pointer[string]
|
||||
|
||||
func init() {
|
||||
profileFast := ""
|
||||
currentPreset.Store(&profileFast)
|
||||
}
|
||||
|
||||
func getCurrentPreset() string {
|
||||
preset := currentPreset.Load()
|
||||
if preset != nil {
|
||||
return *preset
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func setPresetHandler(ctx *gin.Context) {
|
||||
var newPreset string
|
||||
err := ctx.BindJSON(&newPreset)
|
||||
if err != nil {
|
||||
ctx.Status(400)
|
||||
return
|
||||
}
|
||||
|
||||
if newPreset == "" || ffmpeg.IsNVENCPresetValid(newPreset) {
|
||||
log.Println("Update global ffmpeg NVENC preset to ", newPreset)
|
||||
currentPreset.Store(&newPreset)
|
||||
ctx.Status(http.StatusOK)
|
||||
} else {
|
||||
ctx.Status(400)
|
||||
}
|
||||
}
|
||||
|
||||
func getPresetHandler(ctx *gin.Context) {
|
||||
preset := currentPreset.Load()
|
||||
if preset != nil {
|
||||
ctx.JSON(http.StatusOK, *preset)
|
||||
} else {
|
||||
ctx.JSON(http.StatusOK, "")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue