frame pacing fix

This commit is contained in:
Dmitry Sergeev
2026-09-02 00:39:30 +03:00
parent da5ff8ea4a
commit b8cb750fb4
5 changed files with 118 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
package main
import "time"
const guiFrameInterval = time.Second / 60
// videoPollInterval bounds GUI latency when no video producer is waiting.
// It is not a video-rate cap: Next returns immediately whenever a frame
// arrives, including for sources faster than this interval.
const videoPollInterval = 8 * time.Millisecond
func remainingFrameTime(start, now time.Time, interval time.Duration) time.Duration {
remaining := interval - now.Sub(start)
if remaining < 0 {
return 0
}
return remaining
}
func paceFrame(start time.Time) {
if remaining := remainingFrameTime(start, time.Now(), guiFrameInterval); remaining > 0 {
time.Sleep(remaining)
}
}