mirror of https://github.com/jetkvm/kvm.git
Make audio source switching instant with async initialization
When switching audio output source between HDMI and USB, the HDMI audio device (hw:0,0) can take 18-31 seconds to initialize due to hardware characteristics of the TC358743 chip. This caused the UI to freeze during source changes. Changes: - Move startAudio() to background goroutine in SetAudioOutputSource - Move SaveConfig() to background goroutine to avoid blocking on disk I/O - Return immediately after updating in-memory config - Audio will initialize in background while UI remains responsive The in-memory config is updated synchronously so subsequent calls see the new source immediately. Both async operations are protected by their respective mutexes (audioMutex, configLock).
This commit is contained in:
parent
ee23e3bf22
commit
7fc90b86a8
12
audio.go
12
audio.go
|
|
@ -278,14 +278,22 @@ func SetAudioOutputSource(source string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
stopOutputAudio()
|
||||
config.AudioOutputSource = source
|
||||
|
||||
go func() {
|
||||
stopOutputAudio()
|
||||
if err := startAudio(); err != nil {
|
||||
audioLogger.Error().Err(err).Str("source", source).Msg("Failed to start audio output after source change")
|
||||
}
|
||||
}()
|
||||
|
||||
return SaveConfig()
|
||||
go func() {
|
||||
if err := SaveConfig(); err != nil {
|
||||
audioLogger.Error().Err(err).Msg("Failed to save config after audio source change")
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RestartAudioOutput() error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue