Skip to content

Commit 4f47d62

Browse files
committed
[#315] Updates: add advanced audio support
2 parents 55fbd6c + 28a8fa0 commit 4f47d62

30 files changed

+1742
-412
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"name": "JetKVM",
3-
"image": "mcr.microsoft.com/devcontainers/go:1-1.23-bookworm",
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
4+
"runArgs": ["--platform=linux/amd64" ],
45
"features": {
56
"ghcr.io/devcontainers/features/node:1": {
67
// Should match what is defined in ui/package.json
78
"version": "22.15.0"
9+
},
10+
"ghcr.io/devcontainers/features/go:1": {
11+
// Should match what is defined in go.mod
12+
"version": "latest"
813
}
914
},
1015
"mounts": [

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
bin/*
22
static/*
3+
.vscode/
4+
tmp/
5+
.devcontainer/devcontainer-lock.json
36
.idea
47
.DS_Store
8+
*.log
9+
*.tmp
10+
*.code-workspace
511

612
device-tests.tar.gz

DEVELOPMENT.md

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,47 @@
1111

1212
</div>
1313

14+
1415
# JetKVM Development Guide
1516

17+
1618
Welcome to JetKVM development! This guide will help you get started quickly, whether you're fixing bugs, adding features, or just exploring the codebase.
1719

1820
## Get Started
1921

22+
2023
### Prerequisites
2124
- **A JetKVM device** (for full development)
2225
- **[Go 1.24.4+](https://go.dev/doc/install)** and **[Node.js 22.15.0](https://nodejs.org/en/download/)**
2326
- **[Git](https://git-scm.com/downloads)** for version control
2427
- **[SSH access](https://jetkvm.com/docs/advanced-usage/developing#developer-mode)** to your JetKVM device
28+
- **Audio build dependencies:**
29+
- **New in this release:** The audio pipeline is now fully in-process using CGO, ALSA, and Opus. You must run the provided scripts in `tools/` to set up the cross-compiler and build static ALSA/Opus libraries for ARM. See below.
30+
2531

2632
### Development Environment
2733

28-
**Recommended:** Development is best done on **Linux** or **macOS**.
34+
**Recommended:** Development is best done on **Linux** or **macOS**.
35+
36+
#### Apple Silicon (M1/M2/M3) Mac Users
37+
38+
If you are developing on an Apple Silicon Mac, you should use a devcontainer to ensure compatibility with the JetKVM build environment (which targets linux/amd64 and ARM). There are two main options:
39+
40+
- **VS Code Dev Containers**: Open the project in VS Code and use the built-in Dev Containers support. The configuration is in `.devcontainer/devcontainer.json`.
41+
- **Devpod**: [Devpod](https://devpod.sh/) is a fast, open-source tool for running devcontainers anywhere. If you use Devpod, go to **Settings → Experimental → Additional Environmental Variables** and add:
42+
- `DOCKER_DEFAULT_PLATFORM=linux/amd64`
43+
This ensures all builds run in the correct architecture.
44+
- **devcontainer CLI**: You can also use the [devcontainer CLI](https://github.com/devcontainers/cli) to launch the devcontainer from the terminal.
45+
46+
This approach ensures compatibility with all shell scripts, build tools, and cross-compilation steps used in the project.
2947

3048
If you're using Windows, we strongly recommend using **WSL (Windows Subsystem for Linux)** for the best development experience:
3149
- [Install WSL on Windows](https://docs.microsoft.com/en-us/windows/wsl/install)
3250
- [WSL Setup Guide](https://docs.microsoft.com/en-us/windows/wsl/setup/environment)
3351

3452
This ensures compatibility with shell scripts and build tools used in the project.
3553

54+
3655
### Project Setup
3756

3857
1. **Clone the repository:**
@@ -46,16 +65,25 @@ This ensures compatibility with shell scripts and build tools used in the projec
4665
go version && node --version
4766
```
4867

49-
3. **Find your JetKVM IP address** (check your router or device screen)
68+
3. **Set up the cross-compiler and audio dependencies:**
69+
```bash
70+
make dev_env
71+
# This will run tools/setup_rv1106_toolchain.sh and tools/build_audio_deps.sh
72+
# It will clone the cross-compiler and build ALSA/Opus static libs in $HOME/.jetkvm
73+
#
74+
# **Note:** This is required for the new in-process audio pipeline. If you skip this step, audio will not work.
75+
```
76+
77+
4. **Find your JetKVM IP address** (check your router or device screen)
5078

51-
4. **Deploy and test:**
79+
5. **Deploy and test:**
5280
```bash
5381
./dev_deploy.sh -r 192.168.1.100 # Replace with your device IP
5482
```
5583

56-
5. **Open in browser:** `http://192.168.1.100`
84+
6. **Open in browser:** `http://192.168.1.100`
5785

58-
That's it! You're now running your own development version of JetKVM.
86+
That's it! You're now running your own development version of JetKVM, **with in-process audio streaming for the first time.**
5987

6088
---
6189

@@ -71,13 +99,15 @@ npm install
7199

72100
Now edit files in `ui/src/` and see changes live in your browser!
73101

74-
### Modify the backend
102+
103+
### Modify the backend (including audio)
75104

76105
```bash
77-
# Edit Go files (config.go, web.go, etc.)
106+
# Edit Go files (config.go, web.go, internal/audio, etc.)
78107
./dev_deploy.sh -r 192.168.1.100 --skip-ui-build
79108
```
80109

110+
81111
### Run tests
82112

83113
```bash
@@ -93,21 +123,26 @@ tail -f /var/log/jetkvm.log
93123

94124
---
95125

126+
96127
## Project Layout
97128

98129
```
99130
/kvm/
100131
├── main.go # App entry point
101-
├── config.go # Settings & configuration
102-
├── web.go # API endpoints
103-
├── ui/ # React frontend
104-
│ ├── src/routes/ # Pages (login, settings, etc.)
105-
│ └── src/components/ # UI components
106-
└── internal/ # Internal Go packages
132+
├── config.go # Settings & configuration
133+
├── web.go # API endpoints
134+
├── ui/ # React frontend
135+
│ ├── src/routes/ # Pages (login, settings, etc.)
136+
│ └── src/components/ # UI components
137+
├── internal/ # Internal Go packages
138+
│ └── audio/ # In-process audio pipeline (CGO, ALSA, Opus) [NEW]
139+
├── tools/ # Toolchain and audio dependency setup scripts
140+
└── Makefile # Build and dev automation (see audio targets)
107141
```
108142

109143
**Key files for beginners:**
110144

145+
- `internal/audio/` - [NEW] In-process audio pipeline (CGO, ALSA, Opus)
111146
- `web.go` - Add new API endpoints here
112147
- `config.go` - Add new settings here
113148
- `ui/src/routes/` - Add new pages here
@@ -136,9 +171,10 @@ npm install
136171
./dev_device.sh <YOUR_DEVICE_IP>
137172
```
138173

174+
139175
### Quick Backend Changes
140176

141-
*Best for: API or backend logic changes*
177+
*Best for: API, backend, or audio logic changes (including audio pipeline)*
142178

143179
```bash
144180
# Skip frontend build for faster deployment
@@ -206,7 +242,8 @@ curl -X POST http://<IP>/auth/password-local \
206242

207243
---
208244

209-
## Common Issues & Solutions
245+
246+
### Common Issues & Solutions
210247

211248
### "Build failed" or "Permission denied"
212249

@@ -218,6 +255,8 @@ ssh root@<IP> chmod +x /userdata/jetkvm/bin/jetkvm_app_debug
218255
go clean -modcache
219256
go mod tidy
220257
make build_dev
258+
# If you see errors about missing ALSA/Opus or toolchain, run:
259+
make dev_env # Required for new audio support
221260
```
222261

223262
### "Can't connect to device"
@@ -230,6 +269,15 @@ ping <IP>
230269
ssh root@<IP> echo "Connection OK"
231270
```
232271

272+
273+
### "Audio not working"
274+
275+
```bash
276+
# Make sure you have run:
277+
make dev_env
278+
# If you see errors about ALSA/Opus, check logs and re-run the setup scripts in tools/.
279+
```
280+
233281
### "Frontend not updating"
234282

235283
```bash
@@ -244,18 +292,21 @@ npm install
244292

245293
## Next Steps
246294

295+
247296
### Adding a New Feature
248297

249-
1. **Backend:** Add API endpoint in `web.go`
298+
1. **Backend:** Add API endpoint in `web.go` or extend audio in `internal/audio/`
250299
2. **Config:** Add settings in `config.go`
251300
3. **Frontend:** Add UI in `ui/src/routes/`
252301
4. **Test:** Deploy and test with `./dev_deploy.sh`
253302

303+
254304
### Code Style
255305

256306
- **Go:** Follow standard Go conventions
257307
- **TypeScript:** Use TypeScript for type safety
258308
- **React:** Keep components small and reusable
309+
- **Audio/CGO:** Keep C/Go integration minimal, robust, and well-documented. Use zerolog for all logging.
259310

260311
### Environment Variables
261312

Makefile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# --- JetKVM Audio/Toolchain Dev Environment Setup ---
2+
.PHONY: setup_toolchain build_audio_deps dev_env
3+
4+
# Clone the rv1106-system toolchain to $HOME/.jetkvm/rv1106-system
5+
setup_toolchain:
6+
bash tools/setup_rv1106_toolchain.sh
7+
8+
# Build ALSA and Opus static libs for ARM in $HOME/.jetkvm/audio-libs
9+
build_audio_deps: setup_toolchain
10+
bash tools/build_audio_deps.sh
11+
12+
# Prepare everything needed for local development (toolchain + audio deps)
13+
dev_env: build_audio_deps
14+
@echo "Development environment ready."
15+
JETKVM_HOME ?= $(HOME)/.jetkvm
16+
TOOLCHAIN_DIR ?= $(JETKVM_HOME)/rv1106-system
17+
AUDIO_LIBS_DIR ?= $(JETKVM_HOME)/audio-libs
118
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
219
BUILDDATE ?= $(shell date -u +%FT%T%z)
320
BUILDTS ?= $(shell date -u +%s)
@@ -25,9 +42,14 @@ TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort
2542
hash_resource:
2643
@shasum -a 256 resource/jetkvm_native | cut -d ' ' -f 1 > resource/jetkvm_native.sha256
2744

28-
build_dev: hash_resource
45+
build_dev: build_audio_deps hash_resource
2946
@echo "Building..."
30-
$(GO_CMD) build \
47+
GOOS=linux GOARCH=arm GOARM=7 \
48+
CC=$(TOOLCHAIN_DIR)/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc \
49+
CGO_ENABLED=1 \
50+
CGO_CFLAGS="-I$(AUDIO_LIBS_DIR)/alsa-lib-1.2.14/include -I$(AUDIO_LIBS_DIR)/opus-1.5.2/include -I$(AUDIO_LIBS_DIR)/opus-1.5.2/celt" \
51+
CGO_LDFLAGS="-L$(AUDIO_LIBS_DIR)/alsa-lib-1.2.14/src/.libs -lasound -L$(AUDIO_LIBS_DIR)/opus-1.5.2/.libs -lopus -lm -ldl -static" \
52+
go build \
3153
-ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION_DEV)" \
3254
$(GO_RELEASE_BUILD_ARGS) \
3355
-o $(BIN_DIR)/jetkvm_app cmd/main.go
@@ -70,9 +92,14 @@ dev_release: frontend build_dev
7092
rclone copyto bin/jetkvm_app r2://jetkvm-update/app/$(VERSION_DEV)/jetkvm_app
7193
rclone copyto bin/jetkvm_app.sha256 r2://jetkvm-update/app/$(VERSION_DEV)/jetkvm_app.sha256
7294

73-
build_release: frontend hash_resource
95+
build_release: frontend build_audio_deps hash_resource
7496
@echo "Building release..."
75-
$(GO_CMD) build \
97+
GOOS=linux GOARCH=arm GOARM=7 \
98+
CC=$(TOOLCHAIN_DIR)/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc \
99+
CGO_ENABLED=1 \
100+
CGO_CFLAGS="-I$(AUDIO_LIBS_DIR)/alsa-lib-1.2.14/include -I$(AUDIO_LIBS_DIR)/opus-1.5.2/include -I$(AUDIO_LIBS_DIR)/opus-1.5.2/celt" \
101+
CGO_LDFLAGS="-L$(AUDIO_LIBS_DIR)/alsa-lib-1.2.14/src/.libs -lasound -L$(AUDIO_LIBS_DIR)/opus-1.5.2/.libs -lopus -lm -ldl -static" \
102+
go build \
76103
-ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION)" \
77104
$(GO_RELEASE_BUILD_ARGS) \
78105
-o bin/jetkvm_app cmd/main.go

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111

1212
</div>
1313

14-
JetKVM is a high-performance, open-source KVM over IP (Keyboard, Video, Mouse) solution designed for efficient remote management of computers, servers, and workstations. Whether you're dealing with boot failures, installing a new operating system, adjusting BIOS settings, or simply taking control of a machine from afar, JetKVM provides the tools to get it done effectively.
14+
15+
16+
JetKVM is a high-performance, open-source KVM over IP (Keyboard, Video, Mouse, **Audio**) solution designed for efficient remote management of computers, servers, and workstations. Whether you're dealing with boot failures, installing a new operating system, adjusting BIOS settings, or simply taking control of a machine from afar, JetKVM provides the tools to get it done effectively.
17+
18+
19+
20+
1521

1622
## Features
1723

18-
- **Ultra-low Latency** - 1080p@60FPS video with 30-60ms latency using H.264 encoding. Smooth mouse and keyboard interaction for responsive remote control.
24+
- **Ultra-low Latency** - 1080p@60FPS video with 30-60ms latency using H.264 encoding. Smooth mouse, keyboard, and audio for responsive remote control.
25+
- **First-Class Audio Support** - JetKVM now supports in-process, low-latency audio streaming using ALSA and Opus, fully integrated via CGO. No external audio binaries or IPC required—audio is delivered directly from the device to your browser.
1926
- **Free & Optional Remote Access** - Remote management via JetKVM Cloud using WebRTC.
20-
- **Open-source software** - Written in Golang on Linux. Easily customizable through SSH access to the JetKVM device.
27+
- **Open-source software** - Written in Golang (with CGO for audio) on Linux. Easily customizable through SSH access to the JetKVM device.
2128

2229
## Contributing
2330

@@ -31,20 +38,23 @@ The best place to search for answers is our [Documentation](https://jetkvm.com/d
3138

3239
If you've found an issue and want to report it, please check our [Issues](https://github.com/jetkvm/kvm/issues) page. Make sure the description contains information about the firmware version you're using, your platform, and a clear explanation of the steps to reproduce the issue.
3340

41+
42+
3443
# Development
3544

36-
JetKVM is written in Go & TypeScript. with some bits and pieces written in C. An intermediate level of Go & TypeScript knowledge is recommended for comfortable programming.
45+
JetKVM is written in Go & TypeScript, with some C for low-level integration. **Audio support is now fully in-process using CGO, ALSA, and Opus—no external audio binaries required.**
3746

38-
The project contains two main parts, the backend software that runs on the KVM device and the frontend software that is served by the KVM device, and also the cloud.
47+
The project contains two main parts: the backend software (Go, CGO) that runs on the KVM device, and the frontend software (React/TypeScript) that is served by the KVM device and the cloud.
3948

4049
For comprehensive development information, including setup, testing, debugging, and contribution guidelines, see **[DEVELOPMENT.md](DEVELOPMENT.md)**.
4150

4251
For quick device development, use the `./dev_deploy.sh` script. It will build the frontend and backend and deploy them to the local KVM device. Run `./dev_deploy.sh --help` for more information.
4352

53+
4454
## Backend
4555

46-
The backend is written in Go and is responsible for the KVM device management, the cloud API and the cloud web.
56+
The backend is written in Go and is responsible for KVM device management, audio/video streaming, the cloud API, and the cloud web. **Audio is now captured and encoded in-process using ALSA and Opus via CGO, with no external processes or IPC.**
4757

4858
## Frontend
4959

50-
The frontend is written in React and TypeScript and is served by the KVM device. It has three build targets: `device`, `development` and `production`. Development is used for development of the cloud version on your local machine, device is used for building the frontend for the KVM device and production is used for building the frontend for the cloud.
60+
The frontend is written in React and TypeScript and is served by the KVM device. It has three build targets: `device`, `development`, and `production`. Development is used for the cloud version on your local machine, device is used for building the frontend for the KVM device, and production is used for building the frontend for the cloud.

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ var defaultConfig = &Config{
130130
RelativeMouse: true,
131131
Keyboard: true,
132132
MassStorage: true,
133+
Audio: true,
133134
},
134135
NetworkConfig: &network.NetworkConfig{},
135136
DefaultLogLevel: "INFO",

internal/audio/api.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package audio
2+
3+
// StartAudioStreaming launches the in-process audio stream and delivers Opus frames to the provided callback.
4+
func StartAudioStreaming(send func([]byte)) error {
5+
return StartCGOAudioStream(send)
6+
}
7+
8+
// StopAudioStreaming stops the in-process audio stream.
9+
func StopAudioStreaming() {
10+
StopCGOAudioStream()
11+
}

0 commit comments

Comments
 (0)