Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ screen instead; see [macOS](#macos) and [Windows](#windows).

https://github.com/user-attachments/assets/acdf3f31-64fc-4acf-b5c5-ff173d7100a8

In every test below voxl averages 60 FPS with a median latency of 12–99 ms; noVNC
In every test below voxl averages 60 FPS with a median latency of 13–98 ms; noVNC
averages under 8 FPS.

A 16 vCPU AMD EPYC 9334 VM (no GPU), 2560x1600 Xvfb desktop, same workloads, each
stream decoded by a native client that reads a pixel marker drawn into the content.
Cells are FPS (worst second), then latency p50/p99 from the content being drawn to the
frame being decoded. voxl's column is its best run of each test. To reproduce, see
[`bench/`](bench/README.md).
frame being decoded. voxl's column is its best of three runs of each test, and its
numbers (the column and the CPU row) come from a later session than the other
servers', on the same kind of VM, with x264 built with [`patches/x264`](patches/x264).
To reproduce, see [`bench/`](bench/README.md).

| Test | voxl | [selkies](https://github.com/selkies-project/selkies) | [KasmVNC](https://github.com/kasmtech/KasmVNC) | [Neko](https://github.com/m1k1o/neko) | [Neko, tuned](https://github.com/m1k1o/neko) | [Sunshine](https://github.com/LizardByte/Sunshine) | [Sunshine, tuned](https://github.com/LizardByte/Sunshine) | [noVNC](https://github.com/novnc/noVNC) | [Daytona](https://www.daytona.io) |
| ------------------------------ | -------------------------- | ----------------------------------------------------- | ---------------------------------------------- | ------------------------------------- | -------------------------------------------- | -------------------------------------------------- | --------------------------------------------------------- | --------------------------------------- | --------------------------------- |
| Chromium scroll, LAN | **60.1 (59.7), 55/60 ms** | 56.8 (54.0), 85/106 ms | 51.7 (39.5), 99/135 ms | 25.0 (23.7), 156/217 ms | 53.9 (49.9), 128/155 ms | 28.3 (23.5), 88/115 ms | 48.5 (44.0), 94/117 ms | 6.7 (6.3), 198/301 ms | 5.2 (2.5), 306/713 ms |
| Scroll, 10 Mbps / 40 ms RTT | **60.0 (59.4), 82/94 ms** | 55.6 (47.7), 152/261 ms | 8.3 (7.4), 229/249 ms | 24.6 (14.9), 221/737 ms | 46.3 (40.3), 606/831 ms | 27.9 (25.3), 160/179 ms | 51.3 (47.5), 147/162 ms | 2.6 (2.4), 426/678 ms | 1.9 (1.6), 617/798 ms |
| Scroll, 5 Mbps / 60 ms RTT | **60.1 (59.7), 99/109 ms** | 27.9 (19.6), 2.7/3.7 s | 4.9 (3.6), 306/415 ms | 21.7 (3.8), 1.2/3.6 s | stalls | 29.6 (21.9), 178/207 ms | 44.5 (35.2), 164/191 ms | 1.6 (1.4), 637/937 ms | 1.1 (0.9), 1.1/1.2 s |
| 1080p animation, LAN | **60.1 (59.9), 12/16 ms** | 58.7 (55.9), 31/48 ms | 56.7 (51.6), 51/82 ms | 24.8 (23.6), 122/202 ms | 55.6 (50.0), 54/82 ms | 27.1 (22.7), 69/91 ms | 45.6 (40.3), 42/57 ms | 7.7 (7.2), 149/210 ms | 10.5 (8.8), 138/209 ms |
| Animation, 10 Mbps / 40 ms RTT | **60.1 (59.5), 46/71 ms** | 39.3 (31.8), 2.3/3.1 s | 52.9 (49.2), 76/115 ms | 25.1 (9.1), 295/962 ms | 33.3 (25.4), 4.0/7.1 s | 29.7 (26.0), 108/125 ms | 51.1 (44.6), 86/107 ms | 5.8 (5.2), 160/226 ms | 7.4 (7.0), 154/213 ms |
| Animation, 5 Mbps / 60 ms RTT | **60.0 (58.8), 66/92 ms** | 18.4 (15.3), 2.2/4.3 s | 34.1 (26.4), 104/156 ms | 15.2 (8.6), 5.0/9.4 s | stalls | 34.7 (25.4), 123/143 ms | 45.5 (40.9), 114/131 ms | 5.1 (4.7), 174/240 ms | 5.8 (4.4), 189/252 ms |
| Full-screen animation, LAN | **59.8 (54.0), 18/25 ms** | 54.8 (49.8), 54/79 ms | 34.2 (32.5), 83/102 ms | 22.7 (18.0), 2.9/3.3 s | 54.6 (49.7), 54/79 ms | 24.9 (21.7), 73/98 ms | 47.4 (43.4), 46/65 ms | 5.9 (5.2), 184/279 ms | 9.1 (7.2), 154/247 ms |
| Chromium scroll, LAN | **60.0 (58.1), 37/50 ms** | 56.8 (54.0), 85/106 ms | 51.7 (39.5), 99/135 ms | 25.0 (23.7), 156/217 ms | 53.9 (49.9), 128/155 ms | 28.3 (23.5), 88/115 ms | 48.5 (44.0), 94/117 ms | 6.7 (6.3), 198/301 ms | 5.2 (2.5), 306/713 ms |
| Scroll, 10 Mbps / 40 ms RTT | **60.1 (59.6), 80/90 ms** | 55.6 (47.7), 152/261 ms | 8.3 (7.4), 229/249 ms | 24.6 (14.9), 221/737 ms | 46.3 (40.3), 606/831 ms | 27.9 (25.3), 160/179 ms | 51.3 (47.5), 147/162 ms | 2.6 (2.4), 426/678 ms | 1.9 (1.6), 617/798 ms |
| Scroll, 5 Mbps / 60 ms RTT | **60.0 (59.2), 98/115 ms** | 27.9 (19.6), 2.7/3.7 s | 4.9 (3.6), 306/415 ms | 21.7 (3.8), 1.2/3.6 s | stalls | 29.6 (21.9), 178/207 ms | 44.5 (35.2), 164/191 ms | 1.6 (1.4), 637/937 ms | 1.1 (0.9), 1.1/1.2 s |
| 1080p animation, LAN | **60.0 (59.8), 13/18 ms** | 58.7 (55.9), 31/48 ms | 56.7 (51.6), 51/82 ms | 24.8 (23.6), 122/202 ms | 55.6 (50.0), 54/82 ms | 27.1 (22.7), 69/91 ms | 45.6 (40.3), 42/57 ms | 7.7 (7.2), 149/210 ms | 10.5 (8.8), 138/209 ms |
| Animation, 10 Mbps / 40 ms RTT | **60.0 (58.1), 45/72 ms** | 39.3 (31.8), 2.3/3.1 s | 52.9 (49.2), 76/115 ms | 25.1 (9.1), 295/962 ms | 33.3 (25.4), 4.0/7.1 s | 29.7 (26.0), 108/125 ms | 51.1 (44.6), 86/107 ms | 5.8 (5.2), 160/226 ms | 7.4 (7.0), 154/213 ms |
| Animation, 5 Mbps / 60 ms RTT | **60.0 (59.4), 60/84 ms** | 18.4 (15.3), 2.2/4.3 s | 34.1 (26.4), 104/156 ms | 15.2 (8.6), 5.0/9.4 s | stalls | 34.7 (25.4), 123/143 ms | 45.5 (40.9), 114/131 ms | 5.1 (4.7), 174/240 ms | 5.8 (4.4), 189/252 ms |
| Full-screen animation, LAN | **60.0 (59.4), 16/23 ms** | 54.8 (49.8), 54/79 ms | 34.2 (32.5), 83/102 ms | 22.7 (18.0), 2.9/3.3 s | 54.6 (49.7), 54/79 ms | 24.9 (21.7), 73/98 ms | 47.4 (43.4), 46/65 ms | 5.9 (5.2), 184/279 ms | 9.1 (7.2), 154/247 ms |

| Server CPU, X server + streamer (cores) | idle | 1080p animation | scroll | full screen |
| --------------------------------------------------------- | ---- | ---------------- | ---------------- | ---------------- |
| voxl | 0.00 | 1.39 | 1.33 | 1.68 |
| voxl | 0.00 | 1.54 | 1.44 | 2.00 |
| [selkies](https://github.com/selkies-project/selkies) | 1.29 | not measured | 1.54 | 1.80 |
| [KasmVNC](https://github.com/kasmtech/KasmVNC) | 0.00 | 1.97 | 2.07 | 1.82 (at 34 FPS) |
| [Neko](https://github.com/m1k1o/neko) | 1.63 | 2.50 (at 25 FPS) | 2.20 (at 25 FPS) | 2.46 (at 23 FPS) |
Expand Down Expand Up @@ -95,6 +97,12 @@ cargo build --release
On Linux, `--no-default-features` leaves out PulseAudio, and with it desktop audio: a
voxl that can be linked statically (musl) and runs without PulseAudio's libraries.

`nix-shell` and `default.nix` build x264 with the patches in
[`patches/x264`](patches/x264) ([`x264.nix`](x264.nix)), which skip the work x264 does
on macroblocks voxl's damage map marks unchanged: a frame where a small window changed
encodes in about 40% less time, and the stream comes out bit for bit the same. voxl
builds against a stock x264 too, without the savings.

Or install it from [crates.io](https://crates.io/crates/voxl-server) with the same
libraries on your system (the crate is `voxl-server`, the binary is `voxl`):

Expand Down
3 changes: 2 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ rustPlatform.buildRustPackage {
'';

buildInputs = [
x264
# x264 patched to skip the macroblocks voxl's damage map marks unchanged.
(import ./x264.nix {inherit x264;})
libyuv
libopus
libpulseaudio
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: thelamer <ryankuba@gmail.com>
Date: Wed, 4 Nov 2026 23:09:25 -0500
Subject: [PATCH 1/6] Skip constant macroblocks without analysing them

A P macroblock the caller's mb_info marks constant, which the mb_info fast skip in
x264_macroblock_analyse would code as P_SKIP (the reference is the previous frame at this
macroblock's analysis QP or finer, no weighted prediction) and whose P_SKIP vector is zero, is
coded in the slice loop directly: the reference's pixels become the reconstruction, and the
per-macroblock arrays, the 16x16 vectors later macroblocks and the next frame predict from, the
intra border backup, and the cache column the next macroblock's left neighbour comes from are
left as the full path leaves them. Only CAVLC slices without deblocking, MBAFF, or intra refresh
take it, and a row's first macroblock always takes the full path, whose analysis sets the row's
vertical vector limits.

The stream is bit for bit the full path's: single-threaded (the sliced threads' VBV row control
reads the other slices' progress, so it repeats only on one thread), 1080p, 720p and 1366x770,
CRF and VBV, 4:2:0, 4:4:4 and 10-bit, a video box beside still text and a scroll with the
cleanup's quantizer offsets. At 2560x1600 with four sliced threads, a frame where a 256x256
area changed took 3.76 ms where the full path took 4.26 under CRF, and 4.11 against 4.44 under
VBV.
---
encoder/encoder.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index c2effa2..56f9821 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -2756,6 +2756,107 @@ static ALWAYS_INLINE void bitstream_restore( x264_t *h, x264_bs_bak_t *bak, int
}
}

+/* Code the macroblock at (mb_x, mb_y) as the P_SKIP analysis would take for it, without
+ * loading, analysing, or encoding it: one the caller's mb_info marks constant, where the
+ * mb_info fast skip in x264_macroblock_analyse holds (the reference is the previous frame, at
+ * this macroblock's analysis QP or finer, without weighted prediction) and the P_SKIP vector
+ * is zero. A row's first macroblock always takes the full path, whose analysis sets the
+ * row's vertical vector limits every later macroblock of the row searches and compensates
+ * within. The reference's pixels are the reconstruction, and the macroblock's state is left
+ * as x264_macroblock_cache_save leaves a P_SKIP's: the per-macroblock arrays its neighbours
+ * and the next frame read, the intra border backup, and the right column of the cache the next
+ * macroblock takes its left neighbour from. The stream comes out bit for bit as the full path
+ * codes it; returns 0, leaving everything untouched, wherever the full path would decide. */
+static int macroblock_skip_constant( x264_t *h, int mb_x, int mb_y )
+{
+ const int mb_xy = mb_x + mb_y * h->mb.i_mb_stride;
+ if( mb_x == 0 || !(h->fdec->mb_info[mb_xy] & X264_MBINFO_CONSTANT) )
+ return 0;
+ const int s8x8 = h->mb.i_b8_stride;
+ const int s4x4 = h->mb.i_b4_stride;
+ const int b8_xy = 2*(mb_y * s8x8 + mb_x);
+ const int b4_xy = 4*(mb_y * s4x4 + mb_x);
+ const int first = h->sh.i_first_mb;
+
+ /* P_SKIP's vector is zero where a neighbour is unavailable or one predicts from reference 0
+ * with a zero vector (x264_mb_predict_mv_pskip); a median that comes to zero takes the full
+ * path. */
+ int zero = h->mb.slice_table[mb_xy - 1] != first
+ || mb_y == 0 || h->mb.slice_table[mb_xy - h->mb.i_mb_stride] != first;
+ if( !zero )
+ zero = !( h->mb.ref[0][b8_xy - 1] | M32( h->mb.mv[0][b4_xy - 1] ) )
+ || !( h->mb.ref[0][b8_xy - s8x8] | M32( h->mb.mv[0][b4_xy - s4x4] ) );
+ if( !zero )
+ return 0;
+
+ h->mb.i_mb_x = mb_x;
+ h->mb.i_mb_y = mb_y;
+ h->mb.i_mb_xy = mb_xy;
+ h->mb.i_b8_xy = b8_xy;
+ h->mb.i_b4_xy = b4_xy;
+ int qp = x264_ratecontrol_mb_qp( h );
+ if( h->param.rc.i_aq_mode && h->param.analyse.i_subpel_refine < 10 )
+ qp = abs(qp - h->mb.i_last_qp) == 1 ? h->mb.i_last_qp : qp;
+ if( h->fref[0][0]->effective_qp[mb_xy] > qp )
+ return 0;
+ h->fdec->effective_qp[mb_xy] = qp;
+
+ for( int p = 0; p < (CHROMA444 ? 3 : 1); p++ )
+ {
+ int stride = h->fdec->i_stride[p];
+ int off = 16 * mb_x + 16 * mb_y * stride;
+ pixel *dst = &h->fdec->plane[p][off];
+ h->mc.copy[PIXEL_16x16]( dst, stride, &h->fref[0][0]->plane[p][off], stride, 16 );
+ memcpy( &h->intra_border_backup[mb_y&1][p][mb_x*16], dst + 15*stride, 16*SIZEOF_PIXEL );
+ for( int j = 0; j < 16; j++ )
+ h->mb.pic.p_fdec[p][15 + j*FDEC_STRIDE] = dst[15 + j*stride];
+ }
+ if( CHROMA_FORMAT && !CHROMA444 )
+ {
+ int height = 16 >> CHROMA_V_SHIFT;
+ int stride = h->fdec->i_stride[1];
+ int off = 16 * mb_x + height * mb_y * stride;
+ pixel *dst = &h->fdec->plane[1][off];
+ h->mc.copy[PIXEL_16x16]( dst, stride, &h->fref[0][0]->plane[1][off], stride, height );
+ pixel *last = dst + (height - 1) * stride;
+ for( int i = 0; i < 8; i++ )
+ {
+ h->intra_border_backup[mb_y&1][1][mb_x*16 + i] = last[2*i];
+ h->intra_border_backup[mb_y&1][1][mb_x*16 + 8 + i] = last[2*i + 1];
+ }
+ for( int j = 0; j < height; j++ )
+ {
+ h->mb.pic.p_fdec[1][7 + j*FDEC_STRIDE] = dst[14 + j*stride];
+ h->mb.pic.p_fdec[2][7 + j*FDEC_STRIDE] = dst[15 + j*stride];
+ }
+ }
+
+ h->mb.i_type = P_SKIP;
+ h->mb.i_partition = D_16x16;
+ h->mb.i_cbp_luma = h->mb.i_cbp_chroma = 0;
+ h->mb.b_transform_8x8 = 0;
+ h->mb.type[mb_xy] = P_SKIP;
+ h->mb.slice_table[mb_xy] = first;
+ h->mb.partition[mb_xy] = D_16x16;
+ h->mb.i_mb_prev_xy = mb_xy;
+ M64( h->mb.intra4x4_pred_mode[mb_xy] ) = h->param.b_constrained_intra
+ ? (uint8_t)(-1) * 0x0101010101010101ULL : I_PRED_4x4_DC * 0x0101010101010101ULL;
+ h->mb.i_qp = h->mb.i_last_qp;
+ h->mb.qp[mb_xy] = h->mb.i_qp;
+ h->mb.i_last_dqp = 0;
+ memset( h->mb.non_zero_count[mb_xy], 0, sizeof(h->mb.non_zero_count[0]) );
+ h->mb.cbp[mb_xy] = 0;
+ h->mb.mb_transform_size[mb_xy] = 0;
+ M16( &h->mb.ref[0][b8_xy] ) = 0;
+ M16( &h->mb.ref[0][b8_xy + s8x8] ) = 0;
+ for( int j = 0; j < 4; j++ )
+ M128( &h->mb.mv[0][b4_xy + j*s4x4] ) = M128_ZERO;
+ /* The 16x16 vectors later macroblocks and the next frame predict motion from. */
+ for( int i = 0; i < h->i_ref[0]; i++ )
+ M32( h->mb.mvr[0][i][mb_xy] ) = 0;
+ return 1;
+}
+
static intptr_t slice_write( x264_t *h )
{
int i_skip;
@@ -2773,6 +2874,9 @@ static intptr_t slice_write( x264_t *h )
int b_hpel = h->fdec->b_kept_as_ref;
int orig_last_mb = h->sh.i_last_mb;
int thread_last_mb = h->i_threadslice_end * h->mb.i_mb_width - 1;
+ int b_skip_constant = h->fdec->mb_info && h->sh.i_type == SLICE_TYPE_P && !h->param.b_cabac
+ && !SLICE_MBAFF && !PARAM_INTERLACED && !h->sh.b_weighted_pred && !h->param.b_intra_refresh
+ && h->fdec->i_frame - h->fref[0][0]->i_frame == 1;
uint8_t *last_emu_check;
#define BS_BAK_SLICE_MAX_SIZE 0
#define BS_BAK_CAVLC_OVERFLOW 1
@@ -2780,6 +2884,7 @@ static intptr_t slice_write( x264_t *h )
#define BS_BAK_ROW_VBV 3
x264_bs_bak_t bs_bak[4];
b_deblock &= b_hpel || h->param.b_full_recon || h->param.psz_dump_yuv;
+ b_skip_constant &= !b_deblock;
bs_realign( &h->out.bs );

/* Slice */
@@ -2859,6 +2964,29 @@ static intptr_t slice_write( x264_t *h )
h->mb.field[mb_xy] = MB_INTERLACED;
}

+ if( b_skip_constant && !h->mb.b_reencode_mb && macroblock_skip_constant( h, i_mb_x, i_mb_y ) )
+ {
+ i_skip++;
+ if( x264_ratecontrol_mb( h, 0 ) < 0 )
+ {
+ bitstream_restore( h, &bs_bak[BS_BAK_ROW_VBV], &i_skip, 1 );
+ h->mb.b_reencode_mb = 1;
+ i_mb_x = 0;
+ h->mb.i_mb_prev_xy = i_mb_y * h->mb.i_mb_stride - 1;
+ h->sh.i_last_mb = orig_last_mb;
+ continue;
+ }
+ h->stat.frame.i_mb_count[P_SKIP]++;
+ if( mb_xy == h->sh.i_last_mb )
+ break;
+ if( ++i_mb_x == h->mb.i_mb_width )
+ {
+ i_mb_y++;
+ i_mb_x = 0;
+ }
+ continue;
+ }
+
/* load cache */
if( SLICE_MBAFF )
x264_macroblock_cache_load_interlaced( h, i_mb_x, i_mb_y );
Loading
Loading