fix fps toggle
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
package capture
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
const maxInFlightFrames int64 = 2
|
||||
const defaultMaxInFlightFrames int64 = 2
|
||||
|
||||
var (
|
||||
inFlightFrames atomic.Int64
|
||||
frameAckSeen atomic.Bool
|
||||
lastAckNano atomic.Int64
|
||||
maxFrameSlots atomic.Int64
|
||||
)
|
||||
|
||||
func AcquireFrameSlot() bool {
|
||||
@@ -20,7 +24,7 @@ func AcquireFrameSlot() bool {
|
||||
|
||||
for {
|
||||
cur := inFlightFrames.Load()
|
||||
if cur >= maxInFlightFrames {
|
||||
if cur >= activeFrameSlotLimit() {
|
||||
lastAck := lastAckNano.Load()
|
||||
if lastAck > 0 && time.Since(time.Unix(0, lastAck)) > time.Second {
|
||||
inFlightFrames.Store(0)
|
||||
@@ -47,3 +51,33 @@ func ResetFrameSlots() {
|
||||
frameAckSeen.Store(false)
|
||||
lastAckNano.Store(0)
|
||||
}
|
||||
|
||||
func SetFrameFlowTargetFPS(fps int) {
|
||||
limit := defaultMaxInFlightFrames
|
||||
switch {
|
||||
case fps >= 180:
|
||||
limit = 8
|
||||
case fps >= 120:
|
||||
limit = 4
|
||||
}
|
||||
if env := strings.TrimSpace(os.Getenv("OVERLORD_DESKTOP_IN_FLIGHT_FRAMES")); env != "" {
|
||||
if v, err := strconv.Atoi(env); err == nil {
|
||||
switch {
|
||||
case v < 1:
|
||||
limit = 1
|
||||
case v > 32:
|
||||
limit = 32
|
||||
default:
|
||||
limit = int64(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
maxFrameSlots.Store(limit)
|
||||
}
|
||||
|
||||
func activeFrameSlotLimit() int64 {
|
||||
if limit := maxFrameSlots.Load(); limit > 0 {
|
||||
return limit
|
||||
}
|
||||
return defaultMaxInFlightFrames
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user