mirror of https://github.com/jetkvm/kvm.git
Problem: When switching audio sources (USB to HDMI or vice versa), the application would hang indefinitely. This was caused by a deadlock between Go and C layers: 1. Main thread calls SetAudioOutputSource() → stopOutputAudio() 2. stopOutputAudio() calls outputRelay.Stop() which waits for goroutine 3. Goroutine is blocked in ReadMessage() holding Go mutex 4. ReadMessage() calls blocking C function jetkvm_audio_read_encode() 5. C function is blocked reading from ALSA device 6. Disconnect() can't acquire Go mutex to clean up 7. Deadlock: Main thread waiting for goroutine, goroutine waiting for ALSA Solution: Release the Go mutex BEFORE calling blocking C functions in ReadMessage() and WriteMessage(). The C layer has its own pthread mutex protection and handles stop requests via atomic flags. This allows: - Disconnect() to acquire the mutex immediately - C layer to detect stop request and return quickly - Goroutines to exit cleanly - Audio source switching to work flawlessly Fixes: - internal/audio/cgo_source.go:ReadMessage() - Release mutex before C call - internal/audio/cgo_source.go:WriteMessage() - Release mutex before C call This fix eliminates the hang when switching between USB and HDMI audio sources. |
||
|---|---|---|
| .. | ||
| audio | ||
| confparser | ||
| hidrpc | ||
| logging | ||
| mdns | ||
| native | ||
| network/types | ||
| sync | ||
| timesync | ||
| tzdata | ||
| usbgadget | ||
| utils | ||
| websecure | ||