Files
overlord/Overlord-Client/cmd/agent/capture/h264_direct_windows.go
T

63 lines
1.9 KiB
Go
Raw Normal View History

2026-06-06 16:08:28 -05:00
//go:build windows
package capture
import (
"time"
"overlord-client/cmd/agent/webrtcpub"
"overlord-client/cmd/agent/wire"
)
func directVideoKeyframeDue(requested bool, nowNs, lastKeyframeNs int64) bool {
if requested || lastKeyframeNs == 0 {
return true
}
2026-07-30 00:22:08 -05:00
return videoKeyframeEvery > 0 && time.Duration(nowNs-lastKeyframeNs) >= videoKeyframeEvery
}
2026-07-30 08:45:47 -05:00
func directDesktopVideoEnabled() bool {
return useDesktopDuplication()
}
2026-06-06 16:08:28 -05:00
func tryBuildDirectH264Frame(display int) (wire.Frame, time.Duration, time.Duration, bool, error) {
2026-07-21 16:08:45 -05:00
codec := desktopCodec()
2026-07-18 01:27:58 -05:00
if (codec != "h264" && codec != "hevc") || (codec == "h264" && useDesktopSoftwareH264()) || !useDesktopDuplication() {
2026-06-06 16:08:28 -05:00
return wire.Frame{}, 0, 0, false, nil
}
now := time.Now()
2026-07-30 00:22:08 -05:00
requestedKeyframe := webrtcpub.ConsumeKeyframeRequest(webrtcpub.KindDesktop)
forceKeyframe := directVideoKeyframeDue(
2026-07-30 00:22:08 -05:00
requestedKeyframe,
now.UnixNano(),
lastKeyframe.Load(),
)
2026-07-18 01:27:58 -05:00
var data []byte
var width, height int
var captureDur, encodeDur time.Duration
var used bool
var err error
if codec == "hevc" {
data, width, height, captureDur, encodeDur, used, err = captureDisplayDXGIHEVC(display, forceKeyframe)
} else {
data, width, height, captureDur, encodeDur, used, err = captureDisplayDXGIH264(display, forceKeyframe)
}
2026-06-06 16:08:28 -05:00
if !used || err != nil {
2026-07-30 00:22:08 -05:00
if requestedKeyframe {
webrtcpub.RequestKeyframe(webrtcpub.KindDesktop)
}
2026-06-06 16:08:28 -05:00
return wire.Frame{}, captureDur, encodeDur, used, err
}
if len(data) == 0 {
2026-07-30 00:22:08 -05:00
if requestedKeyframe {
webrtcpub.RequestKeyframe(webrtcpub.KindDesktop)
}
2026-06-06 16:08:28 -05:00
return wire.Frame{}, captureDur, encodeDur, true, nil
}
2026-07-30 00:22:08 -05:00
if retainKeyframeRequestUntilOutput(webrtcpub.KindDesktop, requestedKeyframe, codec, data) {
lastKeyframe.Store(now.UnixNano())
}
2026-06-06 16:08:28 -05:00
statFullFrames.Add(1)
2026-07-18 01:27:58 -05:00
return wire.Frame{Type: "frame", Header: wire.FrameHeader{Monitor: display, FPS: 0, Format: codec, Width: width, Height: height}, Data: data}, captureDur, encodeDur, true, nil
2026-06-06 16:08:28 -05:00
}