mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
Release 202412292127
This commit is contained in:
52
video.go
Normal file
52
video.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package kvm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
// max frame size for 1080p video, specified in mpp venc setting
|
||||
const maxFrameSize = 1920 * 1080 / 2
|
||||
|
||||
func writeCtrlAction(action string) error {
|
||||
actionMessage := map[string]string{
|
||||
"action": action,
|
||||
}
|
||||
jsonMessage, err := json.Marshal(actionMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = WriteCtrlMessage(jsonMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
type VideoInputState struct {
|
||||
Ready bool `json:"ready"`
|
||||
Error string `json:"error,omitempty"` //no_signal, no_lock, out_of_range
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
FramePerSecond float64 `json:"fps"`
|
||||
}
|
||||
|
||||
var lastVideoState VideoInputState
|
||||
|
||||
func triggerVideoStateUpdate() {
|
||||
go func() {
|
||||
writeJSONRPCEvent("videoInputState", lastVideoState, currentSession)
|
||||
}()
|
||||
}
|
||||
func HandleVideoStateMessage(event CtrlResponse) {
|
||||
videoState := VideoInputState{}
|
||||
err := json.Unmarshal(event.Data, &videoState)
|
||||
if err != nil {
|
||||
log.Println("Error parsing video state json:", err)
|
||||
return
|
||||
}
|
||||
lastVideoState = videoState
|
||||
triggerVideoStateUpdate()
|
||||
requestDisplayUpdate()
|
||||
}
|
||||
|
||||
func rpcGetVideoState() (VideoInputState, error) {
|
||||
return lastVideoState, nil
|
||||
}
|
||||
Reference in New Issue
Block a user