ok, now we have a gui
This commit is contained in:
+48
-19
@@ -534,13 +534,20 @@ func main() {
|
||||
sdl.SetWindowFullscreen(windowHandler, true)
|
||||
}
|
||||
var (
|
||||
fps float64
|
||||
lastIndex uint64
|
||||
dropped uint64
|
||||
frameCount uint64
|
||||
lastReport time.Time
|
||||
lastFrame time.Time
|
||||
// ImGui stats
|
||||
domainStr string = args.Domain
|
||||
videoStr string = args.VideoFlowId
|
||||
audioStr string = args.AudioFlowId
|
||||
showStats bool = true
|
||||
)
|
||||
lastFrame = time.Now()
|
||||
|
||||
for running {
|
||||
frameStart := time.Now()
|
||||
var event [128]byte
|
||||
@@ -560,6 +567,8 @@ func main() {
|
||||
fullscreen = !fullscreen
|
||||
sdl.SetWindowFullscreen(windowHandler, fullscreen)
|
||||
resized = true
|
||||
case sdl.KeyF1:
|
||||
showStats = !showStats
|
||||
}
|
||||
}
|
||||
gui.ProcessEvent(&event)
|
||||
@@ -600,12 +609,48 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
// stats
|
||||
if lastIndex != 0 && shownIndex > lastIndex {
|
||||
if g := shownIndex - lastIndex - 1; g > 0 {
|
||||
dropped += g
|
||||
}
|
||||
}
|
||||
lastIndex = shownIndex
|
||||
frameCount++
|
||||
if now := time.Now(); now.Sub(lastReport) >= time.Second {
|
||||
dt := now.Sub(lastReport).Seconds()
|
||||
fps = float64(frameCount) / dt
|
||||
fmt.Printf("fps=%.1f dropped=%d idx=%d frameTime=%.2fms\n",
|
||||
fps, dropped, shownIndex, float64(now.Sub(frameStart).Microseconds())/1000.0)
|
||||
frameCount = 0
|
||||
dropped = 0
|
||||
lastReport = now
|
||||
}
|
||||
// end of stats
|
||||
if r != nil {
|
||||
gui.BeginFrame(time.Since(lastFrame), int32(r.Extent().Width), int32(r.Extent().Height))
|
||||
// test widget
|
||||
cimgui.Begin("Test")
|
||||
imguiLabel := fmt.Sprintf("%dx%d", 1920, 1080)
|
||||
cimgui.SeparatorText(imguiLabel)
|
||||
// cimgui.Begin("Test")
|
||||
if showStats {
|
||||
cimgui.SetNextWindowPos(cimgui.Vec2{X: 10, Y: 10})
|
||||
cimgui.SetNextWindowSize(cimgui.Vec2{X: 300, Y: 300})
|
||||
cimgui.BeginV("Stats", &showStats,
|
||||
cimgui.WindowFlagsNoTitleBar|cimgui.WindowFlagsNoBackground|cimgui.WindowFlagsNoResize|cimgui.WindowFlagsNoScrollbar)
|
||||
cimgui.Text(fmt.Sprintf("FPS: %.1f", fps))
|
||||
cimgui.Text(fmt.Sprintf("Dropped: %d", dropped))
|
||||
cimgui.Text(fmt.Sprintf("Index: %d", shownIndex))
|
||||
if syncSrc != nil {
|
||||
cimgui.Text(fmt.Sprintf("Video: %dx%d %.2fp", syncSrc.Width(), syncSrc.Height(),
|
||||
float32(syncSrc.Rate().Num/syncSrc.AudioRate().Den)))
|
||||
cimgui.Text(fmt.Sprintf("Audio: %dch %dkHz", syncSrc.Channels(), syncSrc.AudioRate().Num))
|
||||
}
|
||||
cimgui.End()
|
||||
}
|
||||
cimgui.Begin("Connection")
|
||||
cimgui.InputTextWithHint("Domain", "/dev/shm/mxl", &domainStr, 0, nil)
|
||||
cimgui.InputTextWithHint("Video UUID", "", &videoStr, 0, nil)
|
||||
cimgui.InputTextWithHint("Audio UUID", "", &audioStr, 0, nil)
|
||||
cimgui.Checkbox("Show stats", &showStats)
|
||||
cimgui.End()
|
||||
gui.EndFrame()
|
||||
lastFrame = time.Now()
|
||||
@@ -631,22 +676,6 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if lastIndex != 0 && shownIndex > lastIndex {
|
||||
if g := shownIndex - lastIndex - 1; g > 0 {
|
||||
dropped += g
|
||||
}
|
||||
}
|
||||
lastIndex = shownIndex
|
||||
frameCount++
|
||||
if now := time.Now(); now.Sub(lastReport) >= time.Second {
|
||||
dt := now.Sub(lastReport).Seconds()
|
||||
fps := float64(frameCount) / dt
|
||||
fmt.Printf("fps=%.1f dropped=%d idx=%d frameTime=%.2fms\n",
|
||||
fps, dropped, shownIndex, float64(now.Sub(frameStart).Microseconds())/1000.0)
|
||||
frameCount = 0
|
||||
dropped = 0
|
||||
lastReport = now
|
||||
}
|
||||
} else {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user