Commit Graph

320 Commits

Author SHA1 Message Date
Alex P 9f0d9c4689 Fix: skip redundant USB gadget reconfigurations to prevent HID disruption
- Add Devices.Equals() method to compare USB device configurations
- Add GetGadgetDevices() to retrieve current device state
- Skip gadget reconfiguration when device state is unchanged
- Remove 6 unused audio translation keys from all language files
2025-11-17 22:48:02 +02:00
Alex P 9371868b14 Fix: increase Opus buffer size to 1500 bytes and add bounds check 2025-11-17 22:48:02 +02:00
Alex P 922a7158e7 Add runtime configurable audio parameters with UI controls
- Add config fields for bitrate, complexity, DTX, FEC, buffer periods
- Add RPC methods for get/set audio config and restart
- Add UI settings page with controls for all audio parameters
- Add Apply Settings button to restart audio with new config
- Add config migration for backwards compatibility
- Add translations for all 9 languages
- Clean up redundant comments and optimize log levels
2025-11-17 21:51:08 +02:00
Alex P e79c6f730e Add audio output source switching and improve shutdown handling
- Add HDMI/USB audio source selection in settings UI
- Add stop flags for graceful audio shutdown
- Use immediate PCM drop instead of drain for faster switching
- Add HDMI connection refresh RPC method
- Add GetDefaultEDID helper method
2025-11-17 20:45:34 +02:00
Alex P 9e69a0cb97 Fix: set EDID before video init to ensure audio capability detection 2025-11-17 17:36:53 +02:00
Alex P 17f52414ac Fix: increase ALSA buffer size to reduce audio crackling
Increase buffer from 80ms (4 periods) to 240ms (12 periods) for
better jitter tolerance on USB gadget audio capture.
2025-11-17 13:50:21 +02:00
Alex P 400b3473ae Fix: add stub implementations for non-ARM platforms to fix lint
Adds cgo_source_stub.go with inverse build tag (!linux || (!arm && !arm64))
to provide stub function signatures for CI linting on amd64 runners.
2025-11-17 12:33:07 +02:00
Alex P 98d20d4ffa Merge branch 'dev' into feat/audio-support 2025-11-11 21:40:29 +02:00
Aveline 5fb4c629dd
feat: failsafe mode (#952)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Adam Shiervani <adam.shiervani@gmail.com>
Co-authored-by: Marc Brooks <IDisposable@gmail.com>
2025-11-11 13:13:42 +01:00
Alex P 65531427bd fix: update default EDID to enable audio support
The previous default EDID did not advertise audio capabilities,
preventing HDMI audio capture from working. This update ensures
the JetKVM properly identifies itself to source devices and
enables audio capture out of the box.

Changes:
- Display identifies as "JetKVM HDMI" (manufacturer ID: JTK)
- Includes full audio support (2/6/8-channel LPCM, up to 192 kHz)
- Advertises all TC358743XBG capabilities (1080p60, YCbCr, Deep Color)

This allows HDMI audio to work by default without manual EDID
configuration.
2025-10-30 22:33:04 +02:00
Alex P 65975a196e Merge branch 'dev' into feat/audio-support 2025-10-30 02:14:30 +02:00
Adam Shiervani 1ce63664c0
fix: video quality (#913) 2025-10-29 16:11:07 +01:00
Alex P fbb52e7d27 fix: wait for audio relay goroutine to exit before disconnecting source 2025-10-29 00:44:02 +02:00
Alex P df87d9f5e1 fix: remove continuous sleep mode check to prevent audio interference
The continuous ensure_sleep_mode_disabled() call in the format detection
loop caused repeated I2C transactions to the TC358743, disrupting HDMI
audio capture. Sleep mode is already disabled once during video_init(),
which is sufficient.
2025-10-27 17:28:14 +02:00
Alex P 4e6ae0264a chore: revert golangci-lint config and remove audio stub
- Revert .golangci.yml to dev branch state (removed custom build-tags)
- Remove internal/audio/cgo_source_stub.go (not needed with proper cross-compilation)
- Fix import ordering in ui/src/utils.ts

Use 'make lint-go' for proper ARM cross-compilation environment.
2025-10-24 01:31:06 +03:00
Alex P c3c34c6072 fix: add stub implementation for CGO audio on non-ARM platforms
Provides no-op AudioSource implementations for platforms that don't
support ARM CGO audio (x86_64, darwin, etc.). This allows golangci-lint
to run successfully on any platform without requiring ARM cross-compilation
toolchain.

The stub implementations return errors when called, ensuring that if
they're accidentally used at runtime on non-ARM platforms, it will fail
gracefully with a clear error message rather than undefined symbols.

Build constraints ensure the real CGO implementation is used on linux/arm
and linux/arm64, while stubs are used everywhere else.
2025-10-24 00:04:05 +03:00
Alex P 3b849cc0eb fix: move ipcMsgTypeOpus constant to source.go for cross-platform builds 2025-10-23 23:13:23 +03:00
Marc Brooks 8b7fcb36ac Merge branch 'dev' into feat/audio-support 2025-10-22 16:35:00 -05:00
Aveline 2444817455
chore: disable sleep mode when detecting video format (#887)
Co-authored-by: Adam Shiervani <adam.shiervani@gmail.com>
Co-authored-by: Adam Shiervani <adamshiervani@fastmail.com>
2025-10-17 17:51:02 +02:00
Alex P 34bfa6f2ca Merge branch 'dev' into feat/audio-support
This merge integrates the latest dev branch changes while preserving all
audio support functionality. Key changes include:

- Network stack refactoring: migrated from internal/network to pkg/nmlite
- New NetworkManager architecture with jetdhcpc client
- Function-based config pattern to avoid shared pointer bugs
- Updated UI components for network settings
- GitHub workflow and PR templates

- config.go: Retained AudioOutputSource field in Config struct
- config.go: Kept Audio: true in defaultUsbDevices
- config.go: Set AudioOutputSource: "usb" as default
- config.go: Adopted dev's types.NetworkConfig import path
- config.go: Adopted dev's function-based getDefaultConfig() pattern

1. config.go Config struct: Combined audio fields with dev's network refactoring
2. config.go default config: Adopted dev's function-based pattern while preserving audio defaults
3. ui/src/utils/jsonrpc.ts: Fixed unused error variable in catch block

All linters pass with 0 errors and 0 warnings.
2025-10-17 00:33:32 +03:00
Aveline c775979ccb
feat: refactoring network stack (#878)
Co-authored-by: Adam Shiervani <adam.shiervani@gmail.com>
2025-10-15 18:32:58 +02:00
Alex 7ad72def30 Merge branch 'dev' into feat/audio-support 2025-10-09 22:42:16 +03:00
Aveline cc9ff74276
feat: add HDMI sleep mode (#881) 2025-10-09 14:52:51 +02:00
Alex P 8caa5fc188 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 24ca56ba86 [WIP] Updates: support in-process mode 2025-10-07 09:54:48 +03:00
Alex P aa0b4876c4 [WIP] Updates: support in-process mode 2025-10-07 09:51:08 +03:00
Alex P dcc0851f2b [WIP] Updates: support in-process mode 2025-10-07 08:49:49 +03:00
Alex P 6728c492a1 feat: Optimize audio quality and default to USB audio
Audio quality improvements:
- Enable constrained VBR to prevent bitrate starvation at low volumes
- Increase Opus complexity from 2 to 5 for better quality
- Enable DTX for bandwidth optimization
- Enable FEC (Forward Error Correction)
- Add DTX and FEC signaling in SDP (usedtx=1;useinbandfec=1)

Default configuration changes:
- Change default audio output source from HDMI to USB
- Enable USB Audio device by default
- USB audio works on current stable image (HDMI requires newer device tree)

These changes fix crackling issues at low volumes and provide better
overall audio quality for both USB and HDMI audio paths.
2025-10-07 01:38:42 +03:00
Alex P 3b609d2b67 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 639eecbb93 fix: Add noise gate to prevent amplifying silence artifacts
Add noise gate threshold at peak > 256 (-42dB) to prevent dynamic gain
from amplifying quantization noise and hardware noise floor. This fixes
crackling, buzzing, and static-like noise when HDMI audio is at very
low volume or during silence.

Without the gate, signals below -42dB (peak < 256) would get 8x gain
applied, amplifying noise floor to audible levels. Now these signals
pass through unmodified, eliminating the artifacts.
2025-10-06 22:23:23 +03:00
Alex P 8bd370668c fix: Address linting errors in audio code
- Check SetReadDeadline error in IPC client
- Explicitly ignore Kill() error (process may be dead)
- Remove init() function and rely on explicit ExtractEmbeddedBinaries() call
2025-10-06 22:12:20 +03:00
Alex P 78c3dc3a1e Refactor: Simplify / rewrite Audio 2025-10-06 21:59:44 +03:00
Alex bdd6f4247b
fix: segfault in cGo 2025-10-02 19:15:03 +02:00
Alex P 2aa07e3860 [WIP] Updates: reduce PR complexity 2025-10-02 00:08:42 +03:00
Alex P f5ab13137f [WIP] Updates: reduce PR complexity 2025-10-01 22:58:37 +03:00
Alex P c2d343b0dc [WIP] Updates: reduce PR complexity 2025-10-01 22:54:37 +03:00
Alex P 78a9e6d566 [WIP] Updates: reduce PR complexity 2025-10-01 22:07:45 +03:00
Alex P bf943cc944 [WIP] Updates: reduce PR complexity 2025-10-01 21:20:30 +03:00
Alex P b1b64fc8d2 [WIP] Updates: use native C binaries for audio 2025-10-01 20:13:13 +03:00
Alex P 7fc363789e Updates: integrate all dev branch changes 2025-10-01 15:50:39 +03:00
Alex P c42432b129 [WIP] Updates: update build flows to work with the CGO jetkvm_native 2025-10-01 10:04:42 +03:00
Alex P 1bb036add4 Merge branch 'dev' into feat/audio-support 2025-09-30 20:08:33 +00:00
Alex P 51a8ed958d Cleanup: remove silence detection 2025-09-30 14:32:36 +00:00
Alex P 186f3cfbe0 [WIP] Cleanup: cleanup audio code after HDMI switch 2025-09-30 13:32:56 +00:00
Alex P 11830e1123 [WIP] Fix: crackling sound when seeking forward after migrating to HDMI Audio 2025-09-30 13:14:15 +00:00
Alex P a0685877bc [WIP] Fix: crackling sound when seeking forwars 2025-09-30 13:11:16 +00:00
Alex P 5d24eba58e [WIP] Fix: crackling sound when seeking forwars 2025-09-30 12:58:49 +00:00
Alex P f891f14152 [WIP] Updates: simplify audio system 2025-09-30 12:36:41 +00:00
Alex P 918cdba0b7 Updates: adjust gain to avoid audio artifacts 2025-09-30 12:05:03 +00:00
Alex P 4afaf6023a [WIP] Updates: simplify audio system 2025-09-30 11:41:17 +00:00
Alex P 06399820c4 [WIP] Updates: simplify audio system 2025-09-30 11:03:34 +00:00
Alex P d015542088 [WIP] Updates: simplify audio system 2025-09-30 09:36:19 +00:00
Alex P 36b8f74087 [WIP] Updates: simplify audio system 2025-09-30 09:08:55 +00:00
Alex P c8401cc483 [WIP] Updates: simplify audio system 2025-09-30 09:04:07 +00:00
Aveline 657a177462
feat: jetkvm native in cGo 2025-09-29 14:09:30 +02:00
Alex P e5357a6a11 [WIP] Cleanup: PR Cleanup 2025-09-20 22:57:19 +03:00
Alex P fa0626db0a [WIP] Cleanup: PR Cleanup 2025-09-20 01:14:41 +03:00
Alex P e944df8e82 [WIP] Cleanup: PR Cleanup 2025-09-20 00:57:57 +03:00
Alex P c6428818a6 [WIP] Cleanup: PR Cleanup 2025-09-20 00:54:14 +03:00
Alex P c7dd1da73a [WIP] Cleanup: PR Cleanup 2025-09-20 00:21:09 +03:00
Alex P 7dfc9dc5e9 Merge branch 'dev' into feat/audio-support 2025-09-19 12:41:46 +00:00
Aveline afb146d78c
feat: release keyPress automatically (#796)
* feat: release keyPress automatically

* send keepalive when pressing the key

* remove logging

* clean up logging

* chore: use unreliable channel to send keepalive events

* chore: use ordered unreliable channel for pointer events

* chore: adjust auto release key interval

* chore: update logging for kbdAutoReleaseLock

* chore: update comment for KEEPALIVE_INTERVAL

* fix: should cancelAutorelease when pressed is true

* fix: handshake won't happen if webrtc reconnects

* chore: add trace log for writeWithTimeout

* chore: add timeout for KeypressReport

* chore: use the proper key to send release command

* refactor: simplify HID RPC keyboard input handling and improve key state management

- Updated `handleHidRPCKeyboardInput` to return errors directly instead of keys down state.
- Refactored `rpcKeyboardReport` and `rpcKeypressReport` to return errors instead of states.
- Introduced a queue for managing key down state updates in the `Session` struct to prevent input handling stalls.
- Adjusted the `UpdateKeysDown` method to handle state changes more efficiently.
- Removed unnecessary logging and commented-out code for clarity.

* refactor: enhance keyboard auto-release functionality and key state management

* fix: correct Windows default auto-repeat delay comment from 1ms to 1s

* refactor: send keypress as early as possible

* refactor: replace console.warn with console.info for HID RPC channel events

* refactor: remove unused NewKeypressKeepAliveMessage function from HID RPC

* fix: handle error in key release process and log warnings

* fix: log warning on keypress report failure

* fix: update auto-release keyboard interval to 225

* refactor: enhance keep-alive handling and jitter compensation in HID RPC

- Implemented staleness guard to ignore outdated keep-alive packets.
- Added jitter compensation logic to adjust timer extensions based on packet arrival times.
- Introduced new methods for managing keep-alive state and reset functionality in the Session struct.
- Updated auto-release delay mechanism to use dynamic durations based on keep-alive timing.
- Adjusted keep-alive interval in the UI to improve responsiveness.

* gofmt

* clean up code

* chore: use dynamic duration for scheduleAutoRelease

* Use harcoded timer reset value for now

* fix: prevent nil pointer dereference when stopping timers in Close method

* refactor: remove nil check for kbdAutoReleaseTimers in DelayAutoReleaseWithDuration

* refactor: optimize dependencies in useHidRpc hooks

* refactor: streamline keep-alive timer management in useKeyboard hook

* refactor: clarify comments in useKeyboard hook for resetKeyboardState function

* refactor: reduce keysDownStateQueueSize

* refactor: close and reset keysDownStateQueue in newSession function

* chore: resolve conflicts

* resolve conflicts

---------

Co-authored-by: Adam Shiervani <adam.shiervani@gmail.com>
2025-09-18 13:35:47 +02:00
Aveline 72e3013337
feat: send all paste keystrokes to backend (#789)
* feat: send all paste keystrokes to backend

* feat: cancel paste mode

* wip: send macro using hidRPC channel

* add delay

* feat: allow paste progress to be cancelled

* allow user to override delay

* chore: clear keysDownState

* fix: use currentSession.reportHidRPCKeyboardMacroState

* fix: jsonrpc.go:1142:21: Error return value is not checked (errcheck)

* fix: performance issue of Uint8Array concat

* chore: hide delay option when debugMode isn't enabled

* feat: use clientSide macro if backend doesn't support macros

* fix: update keysDownState handling

* minor issues

* refactor

* fix: send duplicated keyDownState

* chore: add max length for paste text

---------

Co-authored-by: Adam Shiervani <adam.shiervani@gmail.com>
2025-09-18 13:00:57 +02:00
Marc 25b102ac34
fix: ensure that security-key backed SSH keys are supported (#807) 2025-09-17 12:14:45 +02:00
Alex P bf50669e3a perf(audio): add ARM NEON SIMD optimizations for audio processing
Implement SIMD-optimized audio operations using ARM NEON for Cortex-A7 targets
Update Makefile and CI configuration to support NEON compilation flags
Add SIMD implementations for common audio operations including:
- Sample clearing and interleaving
- Volume scaling and format conversion
- Channel manipulation and balance adjustment
- Endianness swapping and prefetching
2025-09-16 18:18:19 +00:00
Marc Brooks cf679978be
fix(timesync): ensure that auto-update waits for time sync (#609)
- Added check to not attempt auto update if time sync is needed and not yet successful (delays 30 second to recheck).
- Added resync of time when DHCP or link state changes if online
- Added conditional* fallback from configured* NTP servers to the IP-named NTP servers, and then to the DNS named ones if that fails
- Added conditional* fallback from the configured* HTTP servers to the default DNS named ones.
- Uses the configuration* option for how many queries to run in parallel
- Added known static IPs for time servers (in case DNS resolution isn't up yet)
- Added time.cloudflare.com to fall-back NTP servers
- Added fallback to NTP via hostnames
- Logs the resultant time (and mode)
2025-09-16 15:37:02 +02:00
Alex P c6951fc57e PR Review Optimization: As recommended, use ternary operators instead of if/else for better readability 2025-09-16 16:17:56 +03:00
Alex P b9733566bc Consistency: keep if block multi-line 2025-09-16 16:08:16 +03:00
Alex P 755e1cef28 Cleanup: removed redundant code 2025-09-16 16:03:20 +03:00
Alex P 53e8422ac7 Cleanup: removed redundant code 2025-09-16 16:00:55 +03:00
Alex P b03a9f1171 Fix: remove misplaced const 2025-09-16 15:52:53 +03:00
Alex P fe19379ef1 Cleanup, Optimizations: Small aaudio optimizations 2025-09-16 15:46:55 +03:00
Alex P 7615b5c3ef Cleanup, Optimizations: Small aaudio optimizations 2025-09-16 15:45:03 +03:00
Alex P ab6a918219 Cleanup, Optimizations: Small aaudio optimizations 2025-09-16 15:37:23 +03:00
Alex P 6d2b8e585a Cleanup: removed redundant code, comments, etc. 2025-09-16 15:31:10 +03:00
Alex P 717d84672f Cleanup: removed redundant code, comments, etc. 2025-09-16 15:23:16 +03:00
Alex P d810f06417 [WIP] Cleanup: removed redundant code 2025-09-16 15:17:49 +03:00
Alex P 26ac27f33d [WIP] Cleanup: removed redundant code 2025-09-16 15:14:00 +03:00
Alex P 410f10ff39 [WIP] Maintainability Improvement: Add debug logging throughout the audio system for easy debugging and troubleshooting 2025-09-16 15:05:08 +03:00
Marc Brooks 80a8b9e9e3
feat: Adds IPv6 disabling feature (#803)
* Allow disabling IPv6

Simply ignores any IPv6 addresses in the lease and doesn't offer them to the RPC
Also fixed display issue for IPv6 link local address.
Fixes https://github.com/orgs/jetkvm/projects/7/views/1?pane=issue&itemId=122761546&issue=jetkvm%7Ckvm%7C685

* Don't listen on disabled addresses in mDNS or web server.

* We have to set the IPv4 and IPv6 modes on the server.
2025-09-16 12:44:56 +02:00
Alex P bbeeaf2a00 [WIP] Maintainability Improvement: Add debug logging throughout the audio system for easy debugging and troubleshooting 2025-09-16 11:27:18 +03:00
Alex P 21d7c87fc7 [WIP] Add debug logging throughout the audio system 2025-09-16 11:26:48 +03:00
Alex P 53b5a0a90c [WIP] Maintainability: Add debug / trace logs to make it easy to debug audio input issues 2025-09-16 11:11:18 +03:00
Alex P 1d275099d2 [WIP] Cleanup: function naming 2025-09-16 07:33:34 +00:00
Alex P 1fca01c64d [WIP] Cleanup: remove unnecessary complexity 2025-09-15 23:00:03 +00:00
Alex P aa8a5fa7e7 [WIP] Simplification: PR Simplification 2025-09-16 00:44:26 +03:00
Alex P 48c62c5912 Fix: pcm_snd_wait won't work when device is busy 2025-09-16 00:32:19 +03:00
Alex P 97b2fe0c32 [WIP] Optimizations: Optimize audio system 2025-09-15 21:22:02 +00:00
Alex P 7c4f884704 [WIP] Fix: add commented code back 2025-09-15 12:04:24 +00:00
Alex P 8e54e2650c [WIP] Cleanpup: Remove audio input quality settings to reduce complexity 2025-09-15 12:02:47 +00:00
Alex P 7b3a8ccb95 Fix: indentation 2025-09-15 14:29:02 +03:00
Alex P a8b0a33116 [WIP] Cleanup / Refinement: PR Review 2025-09-14 21:55:31 +00:00
Alex P 260714c27c Cleanup: Simplify Makefile by exporting all needed env vars at the top 2025-09-12 09:47:11 +00:00
Alex P 176e2a450e Fix: add accidentally removed test file back, devcontainer build process on clean devcontainer 2025-09-12 09:10:31 +00:00
Alex P f6a107efd4 Merge branch 'dev' into feat/audio-support 2025-09-12 01:18:46 +03:00
Aveline ea068414dc
feat: validate ssh public key before saving (#794)
* feat: validate ssh public key before saving

* fix: TestValidSSHKeyTypes
2025-09-11 23:32:40 +02:00
Alex P 59b75116f0 Improvement (Maintainability): Make all C code more manageable by moving it to its own dedicated file 2025-09-11 13:27:10 +03:00
Alex P 0c05f087f6 [WIP] Cleanup: Remove hid optimization code, as it is out of scope 2025-09-09 23:31:58 +00:00
Alex P 5781a0a56a Updates: defer the mutex unlock 2025-09-09 22:03:35 +00:00
Alex P e105a352fa [WIP] Updates, Cleanup: use uint64 for non-negative values 2025-09-09 21:54:36 +00:00