mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-15 07:13:35 -05:00
perf: merge H.264 SPS and PPS into I-frame perf: refactor MJPEG frame detection perf: update log timestamp to millisecond precision perf: update script `update-nanokvm.py` chore: bump Go to 1.23 chore: bump golang.org/x/net to v0.37.0
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package mjpeg
|
|
|
|
import (
|
|
"NanoKVM-Server/common"
|
|
"NanoKVM-Server/proto"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const FrameDetectInterval uint8 = 60
|
|
|
|
func UpdateFrameDetect(c *gin.Context) {
|
|
var req proto.UpdateFrameDetectReq
|
|
var rsp proto.Response
|
|
|
|
if err := proto.ParseFormRequest(c, &req); err != nil {
|
|
rsp.ErrRsp(c, -1, "invalid parameters")
|
|
return
|
|
}
|
|
|
|
var frame uint8 = 0
|
|
if req.Enabled {
|
|
frame = FrameDetectInterval
|
|
}
|
|
|
|
common.GetKvmVision().SetFrameDetect(frame)
|
|
|
|
rsp.OkRsp(c)
|
|
log.Debugf("update frame detect: %t", req.Enabled)
|
|
}
|
|
|
|
func StopFrameDetect(c *gin.Context) {
|
|
var req proto.StopFrameDetectReq
|
|
var rsp proto.Response
|
|
|
|
if err := proto.ParseFormRequest(c, &req); err != nil {
|
|
rsp.ErrRsp(c, -1, "invalid parameters")
|
|
return
|
|
}
|
|
|
|
duration := 10 * time.Second
|
|
if req.Duration > 0 {
|
|
duration = time.Duration(req.Duration) * time.Second
|
|
}
|
|
|
|
vision := common.GetKvmVision()
|
|
|
|
vision.SetFrameDetect(0)
|
|
time.Sleep(duration)
|
|
vision.SetFrameDetect(FrameDetectInterval)
|
|
|
|
rsp.OkRsp(c)
|
|
}
|