kvm/internal
Alex P 0f8b368427 Fix critical error handling and race conditions in audio system
Address 5 critical issues found in comprehensive code review:

1. Opus Encoder Configuration Failures (CRITICAL)
   - Split encoder settings into critical vs non-critical
   - Critical settings (bitrate, VBR, FEC) now fail initialization on error
   - Non-critical settings (complexity, DTX) log warnings but continue
   - Prevents silent audio quality degradation from misconfigured encoder

2. V4L2 Sample Rate Detection Error Reporting (CRITICAL)
   - Add specific error messages for different failure modes
   - Distinguish permission errors, device not found, and no signal
   - Validate detected sample rates are in reasonable range (8-192kHz)
   - Improves debuggability when HDMI audio detection fails

3. Mutex Handling in ALSA Error Recovery (CRITICAL)
   - Refactor handle_alsa_error() to NEVER unlock mutex internally
   - Caller now always responsible for unlocking after checking return
   - Eliminates complex mutex ownership semantics that caused deadlocks
   - Consistent lock/unlock patterns prevent double-unlock bugs

4. Async Audio Start Error Propagation (CRITICAL)
   - Make SetAudioOutputEnabled/SetAudioInputEnabled synchronous
   - Add 5-second timeout for audio initialization
   - Return errors to caller instead of only logging
   - Revert state on failure to maintain consistency
   - Users now get immediate feedback if audio fails to start

5. CgoSource Race Condition (CRITICAL)
   - Hold c.mu mutex during C function calls in ReadMessage/WriteMessage
   - Prevents use-after-free when Disconnect() called concurrently
   - Lock order (c.mu -> capture_mutex) is consistent, no deadlock risk
   - Fixes potential crash from accessing freed ALSA/codec resources

These changes eliminate silent failures, improve error visibility, and
prevent race conditions that could cause crashes or audio degradation.
2025-11-24 20:23:14 +02:00
..
audio Fix critical error handling and race conditions in audio system 2025-11-24 20:23:14 +02:00
confparser feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
hidrpc feat: release keyPress automatically (#796) 2025-09-18 13:35:47 +02:00
logging feat: jetkvm native in cGo 2025-09-29 14:09:30 +02:00
mdns feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
native Update DefaultEDID to force 60Hz video output 2025-11-24 18:06:15 +02:00
network/types chore: make udhcpc the default DHCP client (#990) 2025-11-20 16:48:07 +01:00
ota refactor: OTA (#912) 2025-11-19 15:20:59 +01:00
supervisor feat: add failsafe reason for video max restart attempts reached (#991) 2025-11-20 17:32:54 +01:00
sync feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
timesync feat: refactoring network stack (#878) 2025-10-15 18:32:58 +02:00
tzdata Refactor audio subsystem for improved maintainability 2025-11-19 13:42:51 +02:00
usbgadget Simplify audio configuration and error handling 2025-11-21 00:54:32 +02:00
utils feat: move native to a separate process, again (#964) 2025-11-19 16:02:37 +01:00
websecure feat(websecure): add support for ed25519 certificates (#513) 2025-05-25 11:09:58 +02:00