mirror of https://github.com/jetkvm/kvm.git
Auto-switch audio output to HDMI when USB audio emulation is disabled
This commit is contained in:
parent
0fe9cab988
commit
1e22e007ea
23
jsonrpc.go
23
jsonrpc.go
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go.bug.st/serial"
|
"go.bug.st/serial"
|
||||||
|
|
||||||
|
"github.com/jetkvm/kvm/internal/audio"
|
||||||
"github.com/jetkvm/kvm/internal/hidrpc"
|
"github.com/jetkvm/kvm/internal/hidrpc"
|
||||||
"github.com/jetkvm/kvm/internal/usbgadget"
|
"github.com/jetkvm/kvm/internal/usbgadget"
|
||||||
"github.com/jetkvm/kvm/internal/utils"
|
"github.com/jetkvm/kvm/internal/utils"
|
||||||
|
|
@ -910,7 +911,6 @@ func updateUsbRelatedConfig(wasAudioEnabled bool) error {
|
||||||
inputRelay = nil
|
inputRelay = nil
|
||||||
audioMutex.Unlock()
|
audioMutex.Unlock()
|
||||||
|
|
||||||
// Atomically swap input source
|
|
||||||
inSource := inputSource.Swap(nil)
|
inSource := inputSource.Swap(nil)
|
||||||
|
|
||||||
if inRelay != nil {
|
if inRelay != nil {
|
||||||
|
|
@ -920,6 +920,27 @@ func updateUsbRelatedConfig(wasAudioEnabled bool) error {
|
||||||
(*inSource).Disconnect()
|
(*inSource).Disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-switch to HDMI audio output when USB audio is disabled
|
||||||
|
audioNowEnabled := config.UsbDevices != nil && config.UsbDevices.Audio
|
||||||
|
if wasAudioEnabled && !audioNowEnabled && config.AudioOutputSource == "usb" {
|
||||||
|
config.AudioOutputSource = "hdmi"
|
||||||
|
stopOutputAudio()
|
||||||
|
if audioOutputEnabled.Load() && activeConnections.Load() > 0 && currentAudioTrack != nil {
|
||||||
|
newSource := audio.NewCgoOutputSource("hw:0,0")
|
||||||
|
newSource.SetConfig(getAudioConfig())
|
||||||
|
newRelay := audio.NewOutputRelay(newSource, currentAudioTrack)
|
||||||
|
|
||||||
|
audioMutex.Lock()
|
||||||
|
outputSource = newSource
|
||||||
|
outputRelay = newRelay
|
||||||
|
audioMutex.Unlock()
|
||||||
|
|
||||||
|
if err := newRelay.Start(); err != nil {
|
||||||
|
logger.Warn().Err(err).Msg("Failed to start HDMI audio after USB audio disabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := gadget.UpdateGadgetConfig(); err != nil {
|
if err := gadget.UpdateGadgetConfig(); err != nil {
|
||||||
return fmt.Errorf("failed to write gadget config: %w", err)
|
return fmt.Errorf("failed to write gadget config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue