mirror of https://github.com/jetkvm/kvm.git
fix: prevent race condition in audio output source switching by reading from in-memory state with proper synchronization
This commit is contained in:
parent
cd7a098f76
commit
65bbcf85ad
2
audio.go
2
audio.go
|
|
@ -176,6 +176,7 @@ func SetAudioOutputSource(useUSB bool) error {
|
|||
Bool("new_usb", useUSB).
|
||||
Msg("Switching audio output source")
|
||||
|
||||
oldValue := useUSBForAudioOutput
|
||||
useUSBForAudioOutput = useUSB
|
||||
|
||||
ensureConfigLoaded()
|
||||
|
|
@ -186,6 +187,7 @@ func SetAudioOutputSource(useUSB bool) error {
|
|||
}
|
||||
if err := SaveConfig(); err != nil {
|
||||
audioLogger.Error().Err(err).Msg("Failed to save config")
|
||||
useUSBForAudioOutput = oldValue
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -970,8 +970,13 @@ func rpcSetUsbDeviceState(device string, enabled bool) error {
|
|||
}
|
||||
|
||||
func rpcGetAudioOutputSource() (string, error) {
|
||||
ensureConfigLoaded()
|
||||
return config.AudioOutputSource, nil
|
||||
audioMutex.Lock()
|
||||
defer audioMutex.Unlock()
|
||||
|
||||
if useUSBForAudioOutput {
|
||||
return "usb", nil
|
||||
}
|
||||
return "hdmi", nil
|
||||
}
|
||||
|
||||
func rpcSetAudioOutputSource(source string) error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue