feat: live settings changes mid-stream

Add flinger.SetConfig to update FPS/quality/name/audio/announce without
restarting the stream. Fields that require a restart (source, port,
stream-index) are preserved. The video loop reads the live config each
frame so changes apply immediately, and the GUI Quality/Frame-rate
dropdowns push changes to a running engine.

Verified live: fps 12->33 and JPEG size 210KB->1.3MB on quality change.
This commit is contained in:
2026-09-19 17:37:47 +01:00
parent f25b498fc1
commit 95f47abadb
3 changed files with 128 additions and 6 deletions
+47
View File
@@ -142,3 +142,50 @@ func itoa(v int) string {
}
return string(buf[i:])
}
// TestSetConfig verifies live config updates apply FPS/quality and reject
// invalid values, while preserving fields that can't change live.
func TestSetConfig(t *testing.T) {
cfg := DefaultConfig()
cfg.Source = "pattern"
cfg.Port = 19758
eng, err := New(cfg)
if err != nil {
t.Fatalf("New: %v", err)
}
// Update FPS/quality live.
newCfg := DefaultConfig()
newCfg.Source = "screen" // must be ignored (requires restart)
newCfg.Port = 9999 // must be ignored
newCfg.Quality = 95
newCfg.FPS = 60
if err := eng.SetConfig(newCfg); err != nil {
t.Fatalf("SetConfig: %v", err)
}
got := eng.getCfg()
if got.Quality != 95 {
t.Errorf("quality = %d, want 95", got.Quality)
}
if got.FPS != 60 {
t.Errorf("fps = %d, want 60", got.FPS)
}
// Source/port preserved.
if got.Source != "pattern" {
t.Errorf("source = %q, want pattern (unchanged live)", got.Source)
}
if got.Port != 19758 {
t.Errorf("port = %d, want 19758 (unchanged live)", got.Port)
}
// Invalid config is rejected and current settings kept.
if err := eng.SetConfig(Config{Quality: 200}); err == nil {
t.Error("expected error for invalid quality")
}
got = eng.getCfg()
if got.Quality != 95 {
t.Errorf("quality changed after rejected update: %d", got.Quality)
}
}