diff --git a/cmd/mxl-player/main.go b/cmd/mxl-player/main.go index 639ac56..35385b2 100644 --- a/cmd/mxl-player/main.go +++ b/cmd/mxl-player/main.go @@ -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) } diff --git a/imgui.ini b/imgui.ini index a6f437a..c02e457 100644 --- a/imgui.ini +++ b/imgui.ini @@ -4,7 +4,17 @@ Size=400,400 Collapsed=0 [Window][Test] -Pos=352,204 -Size=554,180 +Pos=60,60 +Size=251,92 +Collapsed=0 + +[Window][Stats] +Pos=10,10 +Size=300,300 +Collapsed=0 + +[Window][Connection] +Pos=676,497 +Size=413,137 Collapsed=0 diff --git a/internal/sdl/sdl.go b/internal/sdl/sdl.go index 74f3d4c..7731b33 100644 --- a/internal/sdl/sdl.go +++ b/internal/sdl/sdl.go @@ -29,6 +29,7 @@ const ( KeyEscape uint32 = 0x1B KeyF uint32 = 0x66 + KeyF1 uint32 = 0x4000003A InitAudio uint32 = 0x00000010 AudioDeviceDefaultPlayback uint32 = 0xFFFFFFFF