feat: add bitrate measurement and quality presets

- sender tracks payload bytes; engine measures stream bitrate over a
  sliding window and exposes it in Status
- GUI status label and tray tooltip show the live bitrate (e.g. 36 Mbps)
- add a Preset dropdown (Low/Medium/High/Ultra) that sets quality+fps
  together and applies live via SetConfig

Verified: 36 Mbps shown for Medium (quality 70 @ 30fps) matches the
wire measurement.
This commit is contained in:
2026-09-19 17:53:49 +01:00
parent 95f47abadb
commit 583274d9e6
4 changed files with 172 additions and 3 deletions
+45
View File
@@ -61,6 +61,7 @@ type App struct {
portEnt *widget.Entry
qualitySel *widget.Select
fpsSel *widget.Select
presetSel *widget.Select
nameEnt *widget.Entry
audioChk *widget.Check
announceChk *widget.Check
@@ -147,6 +148,12 @@ func (g *App) buildUI() {
g.fpsSel = widget.NewSelect([]string{"15", "30", "60"}, g.applyLiveSettings)
g.fpsSel.SetSelected(itoa(g.cfg.FPS))
// Preset: one-click quality/fps combos. Choosing one sets the Quality and
// Frame rate selectors and applies them (live if running). Created after
// the quality/fps selects so applyPreset's references are valid.
g.presetSel = widget.NewSelect([]string{"Low", "Medium", "High", "Ultra"}, g.applyPreset)
g.presetSel.SetSelected("High")
// Audio.
g.audioChk = widget.NewCheck("Capture system audio", nil)
g.audioChk.SetChecked(g.cfg.Audio)
@@ -173,6 +180,7 @@ func (g *App) buildUI() {
{Text: "Port", Widget: g.portEnt},
{Text: "Source", Widget: g.srcSel},
{Text: "Monitor", Widget: g.monSel},
{Text: "Preset", Widget: g.presetSel},
{Text: "Quality", Widget: g.qualitySel},
{Text: "Frame rate", Widget: g.fpsSel},
{Text: "", Widget: g.audioChk},
@@ -241,6 +249,25 @@ func (g *App) selectedMonitorIndex() int {
return g.cfg.StreamIndex
}
// applyPreset applies a named quality/fps preset to the Quality and Frame
// rate selectors, then pushes it live if the engine is running.
func (g *App) applyPreset(string) {
var q, f int
switch g.presetSel.Selected {
case "Low":
q, f = 50, 15
case "Medium":
q, f = 70, 30
case "Ultra":
q, f = 100, 60
default: // High
q, f = 85, 30
}
g.qualitySel.SetSelected(itoa(q))
g.fpsSel.SetSelected(itoa(f))
g.applyLiveSettings("")
}
// applyLiveSettings pushes the current form values (quality, fps, name,
// audio, announce) into a running engine via SetConfig so changes take
// effect without restarting the stream. When the engine is not running it is
@@ -354,6 +381,9 @@ func (g *App) watchStats() {
g.statusLab.Importance = widget.SuccessImportance
}
tip := "TeleportFling · " + frames + " frames, " + dropped + " dropped"
if st.Bitrate > 0 {
tip += " · " + formatBitrate(st.Bitrate)
}
if st.Err != nil {
tip += " · error"
}
@@ -372,12 +402,27 @@ func formatStatus(st flinger.Status) string {
if st.Dropped > 0 {
base += " · " + itoa(int(st.Dropped)) + " dropped"
}
if st.Bitrate > 0 {
base += " · " + formatBitrate(st.Bitrate)
}
if st.Err != nil {
base += "\nError: " + st.Err.Error()
}
return base
}
// formatBitrate renders a bits/sec value in a human-readable form.
func formatBitrate(bps int64) string {
switch {
case bps >= 1_000_000:
return fmt.Sprintf("%.1f Mbps", float64(bps)/1_000_000)
case bps >= 1_000:
return fmt.Sprintf("%.0f kbps", float64(bps)/1_000)
default:
return fmt.Sprintf("%d bps", bps)
}
}
// stop halts the engine and returns the UI to the stopped state.
func (g *App) stop() {
if g.statsDone != nil {