Commit Graph

13 Commits

Author SHA1 Message Date
Alex P f51c372183 Enhancement: Make the code more DRY 2025-11-10 19:09:22 +02:00
Alex P 9e95cc3f8a fix: prevent audio disconnect from blocking new WebRTC sessions
When an old connection closed while a new one started, the audio cleanup
would hold audioMutex for up to 37 seconds during CGO disconnect calls,
blocking the new session from initializing.

Use capture-clear-release pattern to minimize mutex hold time:
- Capture references to sources/relays while holding mutex
- Clear globals immediately so new sessions can proceed
- Release mutex before calling blocking Stop/Disconnect operations

This eliminates the 37-second hang during connection transitions.
2025-11-10 16:54:31 +02:00
Alex P b9705f4bac Revert "refactor: use atomic.Pointer for thread-safe inputSource access"
This reverts commit 41345b0527.
2025-11-10 15:42:10 +02:00
Alex P 41345b0527 refactor: use atomic.Pointer for thread-safe inputSource access
- Replace mutex-protected inputSource with atomic.Pointer for lock-free reads
- Eliminate ~100 mutex operations per second in audio packet hot path
- Add defer pattern for safer mutex unlock in enable/disable functions
- Add error logging for audio write failures
- Consolidate Makefile lint commands for brevity
2025-11-08 00:43:09 +02:00
Alex P ce4ea10551 fix: handle audio track recreation to prevent microphone failures
When browsers recreate audio tracks during long sessions, the backend
now properly handles the new track instead of ignoring it. Old track
handlers detect when they've been superseded and exit cleanly to
prevent goroutine leaks.
2025-11-04 10:40:35 +02:00
Alex P 3448663afa feat: persist audio preferences to backend config
- Add AudioInputAutoEnable and AudioOutputEnabled fields to backend config
- Implement RPC methods for get/set audio input auto-enable preference
- Load audio output enabled state from config on startup
- Make manual microphone toggle call backend to enable audio pipeline
- Auto-enable preference now persists across incognito sessions
- Reset microphone state to off when reaching login pages
- Fix issue where manual mic toggle required auto-enable to be on
2025-11-04 08:52:27 +02:00
Alex P 14b741c3dd temp: disable audio source selection while HDMI audio issues are diagnosed
Temporarily remove the ability to switch between HDMI and USB audio
output sources. The application now uses USB audio (hw:1,0) exclusively
until HDMI audio capture issues are resolved.

Changes:
- Remove AudioOutputSource config field
- Remove audio source switching logic and UI
- Hardcode USB audio output device
- Remove related RPC methods
2025-11-03 10:49:35 +02:00
Alex P 802166ba23 fix: use atomic.Bool for audio source to prevent mutex contention during switching 2025-10-29 00:26:48 +02:00
Alex P 65bbcf85ad fix: prevent race condition in audio output source switching by reading from in-memory state with proper synchronization 2025-10-28 22:11:11 +02:00
Alex P bb5634be58 refactor: Remove subprocess audio infrastructure, use CGO-only
Remove all subprocess-based audio code to simplify the audio system and
reduce complexity. Audio now uses CGO in-process mode exclusively.

Changes:
- Remove subprocess mode: Deleted Supervisor, IPCSource, embed.go
- Remove audio mode selection from UI (Settings → Audio)
- Remove audio mode from backend config (AudioMode field)
- Remove JSON-RPC handlers: getAudioMode/setAudioMode
- Remove Makefile targets: build_audio_output/input/binaries
- Remove standalone C binaries: jetkvm_audio_{input,output}.c
- Remove IPC protocol implementation: ipc_protocol.{c,h}
- Remove unused IPC functions from audio_common.{c,h}
- Simplify audio.go: startAudio() instead of startAudioSubprocesses()
- Update all function calls and comments to remove subprocess references
- Add constants to cgo_source.go (ipcMaxFrameSize, ipcMsgTypeOpus)
- Keep update_opus_encoder_params() for potential future runtime config

Benefits:
- Simpler codebase: -1,734 lines of code
- Better performance: No IPC overhead on embedded hardware
- Easier maintenance: Single audio implementation
- Smaller binary: No embedded audio subprocess binaries

The audio system now works exclusively via CGO direct C function calls,
with ALSA device selection (HDMI vs USB) still configurable via settings.
2025-10-07 13:34:03 +03:00
Alex P 58fad71112 [WIP] Updates: support in-process mode 2025-10-07 08:49:49 +03:00
Alex P 19fe908426 refactor: Simplify audio implementation
Remove dynamic gain code and rely on Opus encoder quality improvements:
- Increase Opus complexity from 2 to 5 for better quality
- Change bandwidth from FULLBAND (20kHz) to SUPERWIDEBAND (16kHz) for better quality at 128kbps
- Disable FEC to allocate all bits to audio quality
- Increase ALSA buffer from 40ms to 80ms for stability

The dynamic gain code was adding complexity without solving the underlying
issue: TC358743 HDMI chip captures digital audio at whatever volume the
source outputs. Users should adjust volume at the source or in their browser.
2025-10-07 00:25:45 +03:00
Alex P 7872ddc8fc Refactor: Simplify / rewrite Audio 2025-10-06 21:59:44 +03:00